ソースを参照

Add 'subghz_bruteforcer/' from commit '02a1df1d46d2a8af1f2a73cc007aa86da95570bd'

git-subtree-dir: subghz_bruteforcer
git-subtree-mainline: 31c865451c05182014c9efc9268d5822b2e36798
git-subtree-split: 02a1df1d46d2a8af1f2a73cc007aa86da95570bd
Willy-JL 2 年 前
コミット
d552c1dd48
58 ファイル変更5833 行追加0 行削除
  1. 81 0
      subghz_bruteforcer/.github/actions/make-release/action.yml
  2. 141 0
      subghz_bruteforcer/.github/check-version.ps1
  3. 251 0
      subghz_bruteforcer/.github/workflows/build-with-firmwware.yml
  4. 188 0
      subghz_bruteforcer/.github/workflows/codeql.yml
  5. 68 0
      subghz_bruteforcer/.github/workflows/version-check.yml
  6. 3 0
      subghz_bruteforcer/.gitignore
  7. 5 0
      subghz_bruteforcer/.gitremotes
  8. 13 0
      subghz_bruteforcer/.idea/.idea.subbrute.dir/.idea/.gitignore
  9. 4 0
      subghz_bruteforcer/.idea/.idea.subbrute.dir/.idea/encodings.xml
  10. 15 0
      subghz_bruteforcer/.idea/.idea.subbrute.dir/.idea/git_toolbox_prj.xml
  11. 8 0
      subghz_bruteforcer/.idea/.idea.subbrute.dir/.idea/indexLayout.xml
  12. 13 0
      subghz_bruteforcer/.idea/.idea.subbrute.dir/.idea/misc.xml
  13. 6 0
      subghz_bruteforcer/.idea/.idea.subbrute.dir/.idea/projectSettingsUpdater.xml
  14. 6 0
      subghz_bruteforcer/.idea/.idea.subbrute.dir/.idea/vcs.xml
  15. 11 0
      subghz_bruteforcer/.vscode/settings.json
  16. 91 0
      subghz_bruteforcer/CHANGELOG.md
  17. 21 0
      subghz_bruteforcer/LICENSE
  18. 136 0
      subghz_bruteforcer/README.md
  19. 12 0
      subghz_bruteforcer/application.fam
  20. 59 0
      subghz_bruteforcer/helpers/gui_top_buttons.c
  21. 23 0
      subghz_bruteforcer/helpers/gui_top_buttons.h
  22. 79 0
      subghz_bruteforcer/helpers/subbrute_radio_device_loader.c
  23. 15 0
      subghz_bruteforcer/helpers/subbrute_radio_device_loader.h
  24. 501 0
      subghz_bruteforcer/helpers/subbrute_worker.c
  25. 56 0
      subghz_bruteforcer/helpers/subbrute_worker.h
  26. 50 0
      subghz_bruteforcer/helpers/subbrute_worker_private.h
  27. 15 0
      subghz_bruteforcer/manifest.yml
  28. 29 0
      subghz_bruteforcer/scenes/subbrute_scene.h
  29. 8 0
      subghz_bruteforcer/scenes/subbrute_scene_config.h
  30. 95 0
      subghz_bruteforcer/scenes/subbrute_scene_load_file.c
  31. 93 0
      subghz_bruteforcer/scenes/subbrute_scene_load_select.c
  32. 104 0
      subghz_bruteforcer/scenes/subbrute_scene_run_attack.c
  33. 87 0
      subghz_bruteforcer/scenes/subbrute_scene_save_name.c
  34. 51 0
      subghz_bruteforcer/scenes/subbrute_scene_save_success.c
  35. 140 0
      subghz_bruteforcer/scenes/subbrute_scene_setup_attack.c
  36. 282 0
      subghz_bruteforcer/scenes/subbrute_scene_setup_extra.c
  37. 95 0
      subghz_bruteforcer/scenes/subbrute_scene_start.c
  38. 30 0
      subghz_bruteforcer/scenes/subbute_scene.c
  39. BIN
      subghz_bruteforcer/screenshots/screenshot_01.png
  40. BIN
      subghz_bruteforcer/screenshots/screenshot_02.png
  41. BIN
      subghz_bruteforcer/screenshots/screenshot_03.png
  42. BIN
      subghz_bruteforcer/screenshots/screenshot_04.png
  43. BIN
      subghz_bruteforcer/screenshots/screenshot_05.png
  44. 220 0
      subghz_bruteforcer/subbrute.c
  45. 3 0
      subghz_bruteforcer/subbrute.h
  46. BIN
      subghz_bruteforcer/subbrute_10px.png
  47. 27 0
      subghz_bruteforcer/subbrute_custom_event.h
  48. 469 0
      subghz_bruteforcer/subbrute_device.c
  49. 74 0
      subghz_bruteforcer/subbrute_device.h
  50. 89 0
      subghz_bruteforcer/subbrute_i.h
  51. 875 0
      subghz_bruteforcer/subbrute_protocols.c
  52. 128 0
      subghz_bruteforcer/subbrute_protocols.h
  53. 150 0
      subghz_bruteforcer/subbrute_settings.c
  54. 21 0
      subghz_bruteforcer/subbrute_settings.h
  55. 346 0
      subghz_bruteforcer/views/subbrute_attack_view.c
  56. 25 0
      subghz_bruteforcer/views/subbrute_attack_view.h
  57. 488 0
      subghz_bruteforcer/views/subbrute_main_view.c
  58. 33 0
      subghz_bruteforcer/views/subbrute_main_view.h

+ 81 - 0
subghz_bruteforcer/.github/actions/make-release/action.yml

@@ -0,0 +1,81 @@
+---
+name: "Action release"
+description: "Steps to build release"
+author: "DerSkythe"
+
+inputs:
+  release_type:
+    description: 'release_type'
+    required: true
+  release_version:
+    description: 'release_version'
+    required: true
+  firmware_version:
+    description: 'firmware_version'
+    required: true
+  repo_self:
+    description: 'REPO_SELF'
+    required: true
+  gh_token:
+    description: 'github_gh_token'
+    required: true
+  owner:
+    description: 'owner'
+    required: true
+  current_tag:
+    description: 'current_tag'
+    required: true
+  remote_tag_info:
+    description: 'remote_tag_info'
+    required: true
+
+# outputs:
+#   make-minor-release:
+#     description: "make-minor-release"
+#     value: ${{ steps.make-minor-release.outputs }}
+#   make-major-release:
+#     description: "make-minor-release"
+#     value: ${{ steps.make-major-release.outputs }}
+
+runs:
+  using: "composite"
+  steps:
+    - name: Minor release
+      if: ${{ inputs.release_type == 2 }}
+      id: make-minor-release
+      uses: softprops/action-gh-release@v1
+      with:
+        tag_name: 'v${{ inputs.release_version }}'
+        name: 'Minor update v${{ inputs.release_version }}'
+        token: ${{ inputs.gh_token }}
+        draft: true
+        generate_release_notes: true
+        #target_commitish: ${{ github.SHA }}
+        append_body: true
+        body: 'Rebuild with new version of firmware.\n\nSee: [CHANGELOG](${{ inputs.firmware_version }}/blob/dev/CHANGELOG.md)\n${{ inputs.remote_tag_info }}'
+        repository: '${{ inputs.repo_self }}'
+
+    - name: Major release
+      if: ${{ inputs.release_type == 1 }}
+      id: make-major-release
+      uses: softprops/action-gh-release@v1
+      with:
+        tag_name: 'v${{ inputs.release_version }}'
+        name: Release v${{ inputs.release_version }}
+        token: ${{ inputs.gh_token }}
+        draft: true
+        generate_release_notes: true
+        #target_commitish: ${{ github.SHA }}
+        append_body: true
+        body: 'New version is rolling out!'
+        repository: '${{ inputs.repo_self }}'
+
+    - name: Update Firmware variable and create UPDATE release if necessary
+      if: ${{ success() }}
+      env:
+        GITHUB_TOKEN: ${{ inputs.gh_token }}
+        OWNER: ${{ inputs.owner }}
+      shell: bash
+      run: |
+          gh variable set FIRMWARE_VERSION -b '${{ inputs.firmware_version }}' -R '${{ inputs.repo_self }}'
+          gh variable set RELEASE_VERSION -b '${{ inputs.release_version }}' -R '${{ inputs.repo_self }}'

+ 141 - 0
subghz_bruteforcer/.github/check-version.ps1

@@ -0,0 +1,141 @@
+########################################
+Set-StrictMode -Version 3.0            #
+$ErrorActionPreference = "Stop"        #
+########################################
+
+[string]$FirmwareVersion = $args[0]
+[string]$ReleaseVersion = $args[1]
+[string]$RepoSelf = $args[2]
+[string]$RepoUnleashed = $args[3]
+[bool]$ForGithubActions = $true
+
+################################################################################################################################
+function CleanInput
+{
+    param(
+        [string]
+        $DurtyString
+    )
+    return $DurtyString -replace ('[^a-zA-Z\d_\-\,\.\t\n\r\:\;]', '')
+}
+
+################################################################################################################################
+
+$Output = @{
+    RELEASE_VERSION = $ReleaseVersion
+    CURRENT_TAG     = $FirmwareVersion
+    REMOTE_TAG_INFO = $FirmwareVersion
+    RELEASE_TYPE = 0
+}
+
+$Release = @(`
+    (CleanInput `
+        (gh release list -L 1 --repo $RepoUnleashed)`
+    ) -split "`t")
+
+$FirmwareVersionNumber = 0
+$StoredFirmwareVersionNumber = 0
+$LatestFirmware = $Release[2]
+if ($Release[2] -match '\-(\d+)$')
+{
+    $FirmwareVersionNumber = [int]($Matches[1])
+}
+else
+{
+    Write-Error ('::error title=Invalid firmware number::Error during execution this tags {0}' -f $FirmwareVersionNumber)
+    exit 1
+}
+if ($FirmwareVersion -match '\-(\d+)$')
+{
+    $StoredFirmwareVersionNumber = [int]($Matches[1])
+}
+else
+{
+    Write-Error ('::error title=Invalid STORED firmware number::Error during execution this version {0}' -f $FirmwareVersion)
+    exit 1
+}
+$Delta = ( [DateTime]::Now - [DateTime]::Parse($Release[3]))
+Write-Host "FirmwareVersionNumber: $FirmwareVersionNumber, Delta: $Delta"
+#exit 0
+
+$NewVersionFw = $false
+Write-Host ('Latest firmware {0}' -f $FirmwareVersionNumber)
+
+$Output.REMOTE_TAG_INFO = Write-Host ('[{0}]({1}/releases/tag/{2})' `
+        -f $LatestFirmware, $RepoUnleashed, $LatestFirmware)
+if (($FirmwareVersionNumber -gt $StoredFirmwareVersionNumber) -and ( $Delta -gt [TimeSpan]::FromMinutes(10)))
+{
+    $Output.REMOTE_TAG_INFO = $LatestFirmware
+    $NewVersionFw = $true
+}
+elseif ($FirmwareVersionNumber -lt $StoredFirmwareVersionNumber)
+{
+    Write-Error ('::error title=Invalid check of stored::Version in repo: {0}, but we think it is {1}' `
+            -f $FirmwareVersionNumber, $StoredFirmwareVersionNumber)
+    exit 1
+}
+
+$PublishDates = (gh api -H "Accept: application/vnd.github+json" `
+        -H "X-GitHub-Api-Version: 2022-11-28" "/repos/$( $RepoSelf )/releases?per_page=1" `
+    | ConvertFrom-Json | Select-Object published_at, created_at)
+$LastPublished = ($null -eq $PublishDates.published_at ? $PublishDates.created_at : $PublishDates.published_at)
+$Delta = ([DateTime]::Now - $LastPublished)
+
+$Release = (gh api -H "Accept: application/vnd.github+json" `
+        -H "X-GitHub-Api-Version: 2022-11-28" "/repos/$( $RepoSelf )/tags?per_page=1" `
+    | ConvertFrom-Json).name
+Write-Host ('Release {0}' -f $Release) -ForegroundColor Gray -BackgroundColor Blue
+$LatestTag = $Release.Substring(1)
+
+$CurrentVersion = [version]::Parse($ReleaseVersion)
+$ParsedRepoVersion = [version]::Parse($LatestTag)
+
+Write-Host ('Current tag:Repos tag {0}, {1}' -f $CurrentVersion, $ParsedRepoVersion) `
+    -ForegroundColor Gray -BackgroundColor Blue
+Write-Debug ('::debug Current tag:Repos tag {0}, {1}' -f $CurrentVersion, $ParsedRepoVersion)
+
+if (($CurrentVersion -lt $ParsedRepoVersion) -and ( $Delta -gt [TimeSpan]::FromMinutes(10)))
+{
+    $Tag = ('{0}.{1}.{2}' -f $ParsedRepoVersion.Major, $ParsedRepoVersion.Minor, $ParsedRepoVersion.Build)
+
+    $Output.RELEASE_VERSION = $Tag
+    $Output.RELEASE_TYPE = 2
+
+    Write-Host ('::warning title=New release!::Release {0}' -f $Tag)
+}
+elseif ( $NewVersionFw )
+{
+    $Tag = ('{0}.{1}.{2}' -f $CurrentVersion.Major, $CurrentVersion.Minor, ($CurrentVersion.Build + 1))
+
+    $Output.RELEASE_VERSION = $Tag
+    $Output.RELEASE_TYPE = 1
+
+    Write-Host ('::warning title=Firmware was changed!::New version is {0}, need to create release {1}' -f $LatestFirmware, $Tag)
+}
+elseif ( ($Delta -gt [TimeSpan]::FromMinutes(10)) -and ($CurrentVersion -gt $ParsedRepoVersion))
+{
+    Write-Host ('::warning title=Invalid version!::Version in settings: {0}, but repo version is {1}. Going to change variable' `
+        -f $CurrentVersion, $ParsedRepoVersion)
+
+    $Output.RELEASE_VERSION = $ParsedRepoVersion
+    $Output.RELEASE_TYPE = 3
+}
+else
+{
+    # none to release
+    Write-Host 'No new versions, sorry'
+}
+
+$Output.CURRENT_TAG = $LatestTag
+
+if($ForGithubActions) {
+    $Plain = New-Object -TypeName "System.Text.StringBuilder";
+    $Output.GetEnumerator() | ForEach-Object {
+        [void]$Plain.Append($_.Key)
+        [void]$Plain.Append('=')
+        [void]$Plain.AppendLine($_.Value)
+    }
+    Write-Output $Plain.ToString()
+} else {
+    $Output
+}

+ 251 - 0
subghz_bruteforcer/.github/workflows/build-with-firmwware.yml

@@ -0,0 +1,251 @@
+name: "Build for Firmware"
+run-name: "Build ${{ inputs.DEPLOY_TARGET }} by @${{ github.ACTOR }}"
+
+on:
+  workflow_dispatch:
+    inputs:
+      version:
+        description: "Enter version to build or left empty for current version"
+        required: false
+        type: string
+  release:
+    types: [created, prereleased]
+  push:
+    paths:
+      - .github/workflows/build-with-firmware.yml
+
+permissions:
+  contents: write
+  packages: write
+
+concurrency:
+  group: firmware-build-${{ vars.FIRMWARE_VERSION }}-${{ vars.RELEASE_VERSION }}
+  cancel-in-progress: false
+
+jobs:
+  build-and-upload:
+    runs-on: ubuntu-latest
+    env:
+      REPO_SELF: ${{ vars.REPO_SELF }}
+      OFW_PATH: "applications_user/subbrute"
+      RELATIVE_PATH: "applications/external/subbrute"
+      CURRENT_VERSION: ${{ vars.RELEASE_VERSION }}
+      RELEASE_VERSION: ${{ vars.RELEASE_VERSION }}
+      ZIP_NAME: ""
+      ZIP_TAG: ""
+      TGZ_NAME: ""
+      TGZ_TAG: ""
+    strategy:
+      fail-fast: false
+      matrix:
+        firmware: [unlshd, official]
+        include:
+          - firmware: unlshd
+            url: ${{ vars.REPO_UNLEASHED }}
+            version: ${{ vars.FIRMWARE_VERSION }}
+            src-included: 0
+          - firmware: official
+            url: ${{ vars.REPO_OFFICIAL }}
+            version: "official"
+            src-included: 0
+    steps:
+      - name: Set version
+        env:
+          INPUT_VERSION: ${{ inputs.version }}
+          CURRENT_VERSION: ${{ env.CURRENT_VERSION }}
+        shell: pwsh
+        run: |
+          $ReleaseVersion = ([string]::IsNullOrWhitespace($env:INPUT_VERSION) ? $env:CURRENT_VERSION : $env:INPUT_VERSION)
+          Write-Output ('RELEASE_VERSION={0}' -f $ReleaseVersion) >> $env:GITHUB_ENV
+
+      - name: Copy Firmware Files
+        uses: actions/checkout@v3
+        with:
+          repository: "${{ matrix.url }}"
+          clean: "true"
+          submodules: "true"
+          ref: "dev"
+
+      - name: Copy Repo Files
+        if: ${{ matrix.src-included == 0 }}
+        uses: actions/checkout@v3
+        with:
+          repository: "${{ vars.REPO_SELF }}"
+          clean: "true"
+          submodules: "true"
+          path: "${{ env.OFW_PATH }}"
+
+      - name: Print vars about state or repo if Unleashed
+        if: ${{ matrix.src-included == 1 }}
+        shell: pwsh
+        run: |
+          git log --pretty=format:'%s by %C(yellow)%an%Creset (%ad)%n %n%b' --date=local --abbrev-commit --max-count=1
+          git submodule set-branch --branch master '${{ env.RELATIVE_PATH }}'
+          git submodule sync '${{ env.RELATIVE_PATH }}'
+          cd '${{ env.OFW_PATH }}'
+          if ( '${{ env.CURRENT_VERSION }}' -ne '${{ env.RELEASE_VERSION }}' ) {
+            Write-Output '::warning title=Different version::Current version is ${{ env.CURRENT_VERSION }} but we trying to build ${{ env.RELEASE_VERSION }}'
+            git checkout tags/v${{ env.RELEASE_VERSION }} -b tmp-build
+
+            if ( $LASTEXITCODE -ne 0 ) {
+              Write-Error '::error title=Cannot checkout to this version::Error during execution checkout to this tag ${{ env.RELEASE_VERSION }}'
+              exit 1
+            }
+          }
+
+          $Output = (git log --pretty=format:'%s by %C(yellow)%an%Creset (%ad)%n %n%b' --date=local --abbrev-commit --max-count=1)
+
+          if ( $LASTEXITCODE -ne 0 ) {
+            Write-Error '::error title=Invalid checkout::Invalid checkout'
+            exit 1
+          }
+          Write-Output ('::notice title=Git output::{0}' -f $Output)
+
+      - name: Print vars about state or repo if Official
+        if: ${{ matrix.src-included == 0 }}
+        shell: pwsh
+        run: |
+          git log --pretty=format:'%s by %C(yellow)%an%Creset (%ad)%n %n%b' --date=local --abbrev-commit --max-count=1
+          cd '${{ env.OFW_PATH }}'
+
+          if ( '${{ env.CURRENT_VERSION }}' -ne '${{ env.RELEASE_VERSION }}' ) {
+            Write-Output '::warning title=Different version::Current version is ${{ env.CURRENT_VERSION }} but we trying to build ${{ env.RELEASE_VERSION }}'
+            git checkout tags/v${{ env.RELEASE_VERSION }} -b tmp-build
+
+            if ( $LASTEXITCODE -ne 0 ) {
+              Write-Error '::error title=Cannot checkout to this version::Error during execution checkout to this tag ${{ env.RELEASE_VERSION }}'
+              exit 1
+            }
+          } else {
+            $Output = (git log --pretty=format:'%s by %C(yellow)%an%Creset (%ad)%n %n%b' --date=local --abbrev-commit --max-count=1)
+
+            if ( $LASTEXITCODE -ne 0 ) {
+              Write-Error '::error title=Invalid checkout::Invalid checkout'
+              exit 1
+            }
+            Write-Output ('::notice title=Git output::{0}' -f $Output)
+          }
+
+      #    - name: Restore FBT
+      #      id: cache-restore
+      #      if: ${{ success() }}
+      #      uses: actions/cache/restore@v3
+      #      with:
+      #        path: |
+      #          build/**
+      #          debug/**
+      #        # An explicit key for restoring and saving the cache
+      #        key: 'fbt=${{ env.FIRMWARE_VERSION }}'
+      #
+      - name: Remove other apps
+        shell: pwsh
+        if: ${{ success() }}
+        # rm to remove problem FAP which includes non-existent files
+        run: |
+          Remove-Item -Force -Recurse ./applications/debug -ErrorAction SilentlyContinue
+          Remove-Item -Force -Recurse ./applications/examples -ErrorAction SilentlyContinue
+      #          New-Item -Force ./tmp -ItemType Directory -ErrorAction SilentlyContinue
+      #          Copy-Item -Force -Recurse ./applications/external/subbrute/ ./tmp/ -ErrorAction SilentlyContinue
+      #          Remove-Item -Force -Recurse ./applications/external/* -ErrorAction SilentlyContinue
+      #          Copy-Item -Force -Recurse /tmp/* ./applications/external/ -ErrorAction SilentlyContinue
+      #          Remove-Item -Force -Recurse ./tmp -ErrorAction SilentlyContinue
+
+      - name: Build Firmware
+        shell: bash
+        if: ${{ success() }}
+        env:
+          FBT_NO_SYNC: 0
+          DIST_SUFFIX: ${{ matrix.version }}
+          WORKFLOW_BRANCH_OR_TAG: release-cfw
+        run: |
+          ./fbt COMPACT=1 DEBUG=0 FBT_NO_SYNC=0
+
+      - name: Build FAPs
+        shell: bash
+        if: ${{ success() }}
+        env:
+          FBT_NO_SYNC: 0
+          DIST_SUFFIX: ${{ matrix.version }}
+          WORKFLOW_BRANCH_OR_TAG: release-cfw
+          # rm to remove problem FAP which includes non-existent files
+        run: |
+          ./fbt COMPACT=1 DEBUG=0 FBT_NO_SYNC=0 fap_dist
+
+      #    - name: Save FBT
+      #      id: cache-save
+      #      if: ${{ success() }}
+      #      uses: actions/cache/save@v3
+      #      with:
+      #        path: |
+      #          build/**
+      #          debug/**
+      #        # An explicit key for restoring and saving the cache
+      #        key: ${{ steps.cache-restore.outputs.cache-primary-key }}
+
+      - name: Create assets
+        if: ${{ success() }}
+        shell: pwsh
+        env:
+          ZIP_NAME: "subghz_bruteforcer_${{ env.RELEASE_VERSION }}_${{ matrix.firmware }}.zip"
+          TGZ_NAME: "subghz_bruteforcer_${{ env.RELEASE_VERSION }}_${{ matrix.firmware }}.tgz"
+        run: |
+          function Format-Bytes {
+            param(
+                  [int]$number
+              )
+              $sizes = 'KB', 'MB', 'GB', 'TB', 'PB'
+              for ($x = 0; $x -lt $sizes.count; $x++) {
+                  if ($number -lt [int64]"1$($sizes[$x])") {
+                      if ($x -eq 0) {
+                          return "$number B"
+                      }
+                      else {
+                          $num = $number / [int64]"1$($sizes[$x-1])"
+                          $num = "{0:N2}" -f $num
+                          return "$num $($sizes[$x-1])"
+                      }
+                  }
+              }
+          }
+          $ZipName = $env:ZIP_NAME
+          $TgzName = $env:TGZ_NAME
+          $FapNamme = 'subghz_bruteforcer.fap'
+          $DstFap = "./$FapNamme"
+          $AppDir = "dist/f7-C/apps/Sub-GHz"
+
+          if (!(Test-Path -Path "$AppDir/$FapNamme" -PathType Leaf)) {
+              Write-Error '::error title=Files not found::Cannot find files in location'
+              exit 1
+          }
+
+          $Size = (Get-Item -Path "$AppDir/$FapNamme" | Get-ItemPropertyValue -Name Length)
+          Write-Output ('Filesize: {0}' -f (Format-Bytes $Size))
+          Copy-Item -Force -Verbose -Path "$AppDir/$FapNamme" -Destination $DstFap
+
+          zip -r -qq $ZipName $DstFap
+          tar zcf $TgzName $DstFap
+
+          if ( !(Test-Path -Path $ZipName -PathType Leaf) -or !(Test-Path -Path $TgzName -PathType Leaf) ) {
+              Write-Error '::error title=Files not found::Cannot find files in location'
+              exit 1
+          }
+
+          $ZipSize = Format-Bytes (Get-Item -Path $ZipName).Length
+          $TgzSize = Format-Bytes (Get-Item -Path $TgzName ).Length
+
+          Write-Output ('ZIP_NAME={0}' -f $ZipName) >> $env:GITHUB_ENV
+          Write-Output ('TGZ_NAME={0}' -f $TgzName ) >> $env:GITHUB_ENV
+          Write-Output ('ZIP_TAG={0} ({1})' -f $ZipName, $ZipSize) >> $env:GITHUB_ENV
+          Write-Output ('TGZ_TAG={0} ({1})' -f $TgzName , $TgzSize) >> $env:GITHUB_ENV
+
+      - name: Upload assets
+        if: ${{ success() && env.ZIP_NAME != '' }}
+        env:
+          GITHUB_TOKEN: ${{ secrets.FLIPPER_TOKEN }}
+        run: |
+          gh release create v${{ env.RELEASE_VERSION }} --generate-notes --draft -R ${{ env.REPO_SELF }}
+          gh release upload 'v${{ env.RELEASE_VERSION }}' '${{ env.ZIP_NAME }}#${{ env.ZIP_TAG }}' \
+            '${{ env.TGZ_NAME }}#${{ env.TGZ_TAG }}' --clobber -R ${{ env.REPO_SELF }}
+          gh release edit 'v${{ env.RELEASE_VERSION }}' --draft=false -R ${{ env.REPO_SELF }}
+
+#EOF

+ 188 - 0
subghz_bruteforcer/.github/workflows/codeql.yml

@@ -0,0 +1,188 @@
+# For most projects, this workflow file will not need changing; you simply need
+# to commit it to your repository.
+#
+# You may wish to alter this file to override the set of languages analyzed,
+# or to provide custom queries or build logic.
+#
+# ******** NOTE ********
+# We have attempted to detect the languages in your repository. Please check
+# the `language` matrix defined below to confirm you have the correct set of
+# supported CodeQL languages.
+#
+name: "CodeQL"
+
+on:
+  push:
+    branches: ["master", "feat/ci"]
+  pull_request:
+    # The branches below must be a subset of the branches above
+    branches: ["master"]
+  schedule:
+    - cron: "43 14 * * *"
+  workflow_dispatch:
+
+jobs:
+  analyze:
+    name: Analyze
+    # Runner size impacts CodeQL analysis time. To learn more, please see:
+    #   - https://gh.io/recommended-hardware-resources-for-running-codeql
+    #   - https://gh.io/supported-runners-and-hardware-resources
+    #   - https://gh.io/using-larger-runners
+    # Consider using larger runners for possible analysis time improvements.
+    runs-on: "ubuntu-latest"
+    timeout-minutes: 360
+    permissions:
+      actions: read
+      contents: read
+      security-events: write
+
+    strategy:
+      fail-fast: false
+      matrix:
+        language: ["cpp"]
+        # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby', 'swift' ]
+        # Use only 'java' to analyze code written in Java, Kotlin or both
+        # Use only 'javascript' to analyze code written in JavaScript, TypeScript or both
+        # Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support
+    env:
+      REPO_SELF: ${{ vars.REPO_SELF }}
+      OFW_PATH: "applications_user/subbrute"
+      RELATIVE_PATH: "applications/external/subbrute"
+      CURRENT_VERSION: ${{ vars.RELEASE_VERSION }}
+      RELEASE_VERSION: ${{ vars.RELEASE_VERSION }}
+      TOKEN: ${{ secrets.DEPENDABOT }}
+      REF_NAME: ${{ github.ref_name }}
+
+    steps:
+      - name: Checkout Firmware Files
+        uses: actions/checkout@v3
+        with:
+          repository: "${{ vars.REPO_UNLEASHED }}"
+          clean: "true"
+          submodules: "true"
+          ref: "dev"
+          fetch-depth: "0"
+
+      - name: Checkout Repo Files
+        uses: actions/checkout@v3
+        with:
+          repository: "${{ vars.REPO_SELF }}"
+          clean: "true"
+          submodules: "true"
+          path: "${{ env.OFW_PATH }}"
+          fetch-depth: "0"
+
+      - name: Remove other apps
+        shell: pwsh
+        if: ${{ success() }}
+        # rm to remove problem FAP which includes non-existent files
+        run: |
+          Remove-Item -Force -Recurse ./applications/debug -ErrorAction SilentlyContinue
+          Remove-Item -Force -Recurse ./applications/examples -ErrorAction SilentlyContinue
+
+      - name: Set refname
+        env:
+          REF_NAME: ${{ env.REF_NAME }}
+        shell: pwsh
+        run: |
+          $ReleaseVersion = ([string]::IsNullOrWhitespace($env:REF_NAME) ? 'dev' : $env:REF_NAME)
+          Write-Output ('REF_NAME={0}' -f $ReleaseVersion) >> $env:GITHUB_ENV
+
+      # Initializes the CodeQL tools for scanning.
+      - name: Initialize CodeQL
+        uses: github/codeql-action/init@v2
+        with:
+          languages: ${{ matrix.language }}
+          setup-python-dependencies: true
+          #debug: true
+          # If you wish to specify custom queries, you can do so here or in a config file.
+          # By default, queries listed here will override any specified in a config file.
+          # Prefix the list here with "+" to use these queries and those in the config file.
+
+          # For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
+          # queries: security-extended,security-and-quality
+
+      # - name: Restore cached FW
+      #   id: cache-fw-restore
+      #   uses: actions/cache/restore@v3
+      #   with:
+      #     path: |
+      #       ./build
+      #       ./dist
+      #       ./firmware
+      #     key: ${{ runner.os }}-fw
+
+      - name: Build Firmware
+        shell: bash
+        if: ${{ success() }}
+        env:
+          FBT_NO_SYNC: 0
+          DIST_SUFFIX: "codeql"
+          WORKFLOW_BRANCH_OR_TAG: release-cfw
+        run: |
+          ./fbt COMPACT=1 DEBUG=0 FBT_NO_SYNC=${{ env.FBT_NO_SYNC }}
+
+      - name: Build FAPs
+        shell: bash
+        if: ${{ success() }}
+        env:
+          FBT_NO_SYNC: 0
+          DIST_SUFFIX: "codeql"
+          WORKFLOW_BRANCH_OR_TAG: release-cfw
+        # rm to remove problem FAP which includes non-existent files
+        run: |
+          ./fbt COMPACT=1 DEBUG=0 FBT_NO_SYNC=${{ env.FBT_NO_SYNC }} fap_dist
+
+      # - name: Save cached FW
+      #   id: cache-primes-save
+      #   uses: actions/cache/save@v3
+      #   with:
+      #     path: |
+      #       ./build
+      #       ./dist
+      #       ./firmware
+      #     key: ${{ steps.cache-fw-restore.outputs.cache-primary-key }}
+
+      # Autobuild attempts to build any compiled languages (C/C++, C#, Go, Java, or Swift).
+      # If this step fails, then you should remove it and run the build manually (see below)
+      #- name: Autobuild
+      #  run: |
+      #     echo "Run, Build Application using script"
+      #     ls -lha
+      #     ./fbt
+      # uses: github/codeql-action/autobuild@v2
+      - name: Resolve CodeQL Build Env
+        uses: github/codeql-action/resolve-environment@v2
+        with:
+          language: ${{ matrix.language }}
+
+      - name: Perform CodeQL Analysis
+        uses: github/codeql-action/analyze@v2
+        env:
+          REF_NAME: ${{ env.REF_NAME }}
+          CHECKOUT_PATH: ${{ env.OFW_PATH }}
+        with:
+          category: "/language:${{matrix.language}}"
+          token: ${{ secrets.DEPENDABOT }}
+          # Must be used only with sha
+          #ref: ${{ env.REF_NAME }}
+          #sha: ${{ github.sha }}
+          output: "a${{ env.CHECKOUT_PATH }}/.github/results.sarif"
+          check_name: "_"
+          upload-database: false
+          upload: "failure-only"
+          checkout_path: "${{ github.workspace }}/${{ env.CHECKOUT_PATH }}"
+
+      - name: Upload CodeQL SARIF
+        uses: github/codeql-action/upload-sarif@v2
+        env:
+          REF_NAME: ${{ env.REF_NAME }}
+          CHECKOUT_PATH: ${{ env.OFW_PATH }}
+        with:
+          category: "/language:${{matrix.language}}"
+          #token: ${{ secrets.DEPENDABOT }}
+          # Must be used only with sha
+          #ref: ${{ env.REF_NAME }}
+          #sha: ${{ github.sha }}
+          sarif_file: "a${{ env.CHECKOUT_PATH }}/.github/results.sarif"
+          checkout_path: "${{ github.workspace }}/${{ env.CHECKOUT_PATH }}"

+ 68 - 0
subghz_bruteforcer/.github/workflows/version-check.yml

@@ -0,0 +1,68 @@
+name: "Version check for NEW release"
+run-name: " Version check for NEW release ${{ inputs.DEPLOY_TARGET }} by @${{ github.ACTOR }}"
+
+on:
+  workflow_dispatch:
+  push:
+    branches:
+      - master
+  schedule:
+    - cron: "*/30 * * * *"
+
+permissions:
+  contents: write
+
+jobs:
+  pull-request:
+    concurrency:
+      group: check-for-new-versions
+      cancel-in-progress: false
+    runs-on: ubuntu-latest
+    env:
+      REPO_UNLEASHED: ${{ vars.REPO_UNLEASHED }}
+      CURRENT_TAG: ${{ vars.FIRMWARE_VERSION }}
+      REMOTE_TAG_INFO: ''
+      RELEASE_VERSION: ${{ vars.RELEASE_VERSION }}
+      FIRMWARE_VERSION: ${{ vars.FIRMWARE_VERSION }}
+      REPO_SELF: ${{ vars.REPO_SELF }}
+      CHECKOUT_DIR: "firmware"
+      RELEASE_TYPE: 0
+    steps:
+      - name: Copy Repo Files
+        uses: actions/checkout@v3
+        with:
+          repository: "${{ env.REPO_SELF }}"
+          clean: "true"
+          submodules: "true"
+          token: ${{ secrets.FLIPPER_TOKEN }}
+      - name: Check firmware release
+        shell: pwsh
+        env:
+          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+        run: |
+          ./.github/check-version.ps1 '${{ env.FIRMWARE_VERSION }}' '${{ env.RELEASE_VERSION }}' '${{ env.REPO_SELF }}' '${{ env.REPO_UNLEASHED }}' | %{ Write-Output($_) >> $Env:GITHUB_ENV }
+      - name: Print env values
+        run: env
+
+      - name: Create release if necessary
+        if: ${{ success() && (env.RELEASE_TYPE == 2  || env.RELEASE_TYPE == 1 )}}
+        uses: ./.github/actions/make-release
+        with:
+          gh_token: ${{ secrets.FLIPPER_TOKEN }}
+          release_type: ${{ env.RELEASE_TYPE }}
+          release_version: ${{ env.RELEASE_VERSION }}
+          firmware_version: ${{ env.REMOTE_TAG_INFO }}
+          repo_self: ${{ env.REPO_SELF }}
+          owner: ${{ github.repository_owner }}
+          current_tag: ${{ env.CURRENT_TAG }}
+          remote_tag_info: ${{ env.REMOTE_TAG_INFO }}
+
+      - name: Current settings in repo invalid. Changing
+        if: ${{ success() && env.RELEASE_TYPE > 2 }}
+        env:
+          GITHUB_TOKEN: ${{ secrets.FLIPPER_TOKEN }}
+          OWNER: ${{ github.repository_owner }}
+        run: |
+          gh variable set RELEASE_VERSION -b ${{ env.RELEASE_VERSION }} -R ${{ env.REPO_SELF }}
+
+# EOF

+ 3 - 0
subghz_bruteforcer/.gitignore

@@ -0,0 +1,3 @@
+/.idea/.idea.subbrute.dir/.idea/workspace.xml
+
+.DS_Store

+ 5 - 0
subghz_bruteforcer/.gitremotes

@@ -0,0 +1,5 @@
+[remote "upstream"]
+    url = https://github.com/DarkFlippers/flipperzero-subbrute
+    fetch = +refs/heads/*:refs/remotes/subghz-bruteforcer/*
+[alias]
+    merge-upstream = pull --no-edit upstream master

+ 13 - 0
subghz_bruteforcer/.idea/.idea.subbrute.dir/.idea/.gitignore

@@ -0,0 +1,13 @@
+# Default ignored files
+/shelf/
+/workspace.xml
+# Rider ignored files
+/modules.xml
+/contentModel.xml
+/.idea.subbrute.iml
+/projectSettingsUpdater.xml
+# Editor-based HTTP Client requests
+/httpRequests/
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml

+ 4 - 0
subghz_bruteforcer/.idea/.idea.subbrute.dir/.idea/encodings.xml

@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="Encoding" addBOMForNewFiles="with BOM under Windows, with no BOM otherwise" />
+</project>

+ 15 - 0
subghz_bruteforcer/.idea/.idea.subbrute.dir/.idea/git_toolbox_prj.xml

@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="GitToolBoxProjectSettings">
+    <option name="commitMessageIssueKeyValidationOverride">
+      <BoolValueOverride>
+        <option name="enabled" value="true" />
+      </BoolValueOverride>
+    </option>
+    <option name="commitMessageValidationEnabledOverride">
+      <BoolValueOverride>
+        <option name="enabled" value="true" />
+      </BoolValueOverride>
+    </option>
+  </component>
+</project>

+ 8 - 0
subghz_bruteforcer/.idea/.idea.subbrute.dir/.idea/indexLayout.xml

@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="UserContentModel">
+    <attachedFolders />
+    <explicitIncludes />
+    <explicitExcludes />
+  </component>
+</project>

+ 13 - 0
subghz_bruteforcer/.idea/.idea.subbrute.dir/.idea/misc.xml

@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="ActiveTabHighlighterConfiguration">
+    <option name="background">
+      <PersistentColor>
+        <option name="enabled" value="true" />
+        <option name="red" value="173" />
+        <option name="green" value="46" />
+        <option name="blue" value="156" />
+      </PersistentColor>
+    </option>
+  </component>
+</project>

+ 6 - 0
subghz_bruteforcer/.idea/.idea.subbrute.dir/.idea/projectSettingsUpdater.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="RiderProjectSettingsUpdater">
+    <option name="vcsConfiguration" value="2" />
+  </component>
+</project>

+ 6 - 0
subghz_bruteforcer/.idea/.idea.subbrute.dir/.idea/vcs.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="VcsDirectoryMappings">
+    <mapping directory="" vcs="Git" />
+  </component>
+</project>

+ 11 - 0
subghz_bruteforcer/.vscode/settings.json

@@ -0,0 +1,11 @@
+{
+    "githubPullRequests.ignoredPullRequestBranches": [
+        "master"
+    ],
+    "workbench.colorCustomizations": {
+        "list.errorForeground": "#00AA00",
+        "list.warningForeground": "#00d9ff",
+        "gitDecoration.modifiedResourceForeground": "#00ffb3",
+        "gitDecoration.untrackedResourceForeground": "#f7aeae"
+    }
+}

+ 91 - 0
subghz_bruteforcer/CHANGELOG.md

@@ -0,0 +1,91 @@
+# Changelog
+
+
+## [v3.9.0](https://github.com/DarkFlippers/flipperzero-subbrute/tree/v3.9.0) (2023-08-27)
+
+**Merged pull requests:**
+
+* Sync working tree by @derskythe in https://github.com/DarkFlippers/flipperzero-subbrute/pull/11
+* Sync branch by @derskythe in https://github.com/DarkFlippers/flipperzero-subbrute/pull/24
+* Sync by @derskythe in https://github.com/DarkFlippers/flipperzero-subbrute/pull/27
+* Sync from master by @derskythe in https://github.com/DarkFlippers/flipperzero-subbrute/pull/35
+* Create codeql.yml by @derskythe in https://github.com/DarkFlippers/flipperzero-subbrute/pull/36
+* Feat/codeql by @derskythe in https://github.com/DarkFlippers/flipperzero-subbrute/pull/37
+* Feat/save settings by @derskythe in https://github.com/DarkFlippers/flipperzero-subbrute/pull/38
+
+**Full Changelog**: [v3.8.0...v.3.9.0](https://github.com/DarkFlippers/flipperzero-subbrute/compare/v3.8.0...v.3.9.0)
+
+## [v3.8.0](https://github.com/DarkFlippers/flipperzero-subbrute/tree/v3.8.0) (2023-08-25)
+
+* Feat/ofw by @derskythe in https://github.com/DarkFlippers/flipperzero-subbrute/pull/33
+* Feat/save settings by @derskythe in https://github.com/DarkFlippers/flipperzero-subbrute/pull/38
+* Sync by @derskythe in https://github.com/derskythe/flipperzero-subbrute/pull/12
+* feat: ci was added by @derskythe in https://github.com/derskythe/flipperzero-subbrute/pull/10
+* Feat/ci by @derskythe in https://github.com/derskythe/flipperzero-subbrute/pull/13
+* Feat/ci by @derskythe in https://github.com/derskythe/flipperzero-subbrute/pull/14
+* Feat/ci by @derskythe in https://github.com/derskythe/flipperzero-subbrute/pull/15
+
+**Full Changelog**: [v3.7.0...v.3.8.0](https://github.com/DarkFlippers/flipperzero-subbrute/compare/v3.7.0...v.3.8.0)
+
+## [v3.7.0](https://github.com/DarkFlippers/flipperzero-subbrute/tree/v3.7.0) (2023-08-25)
+
+**Closed issues:**
+
+- Holtek 12 bit AM issue [\#23](https://github.com/DarkFlippers/flipperzero-subbrute/issues/23)
+- HORMANN \(HOERMANN\) support? [\#20](https://github.com/DarkFlippers/flipperzero-subbrute/issues/20)
+
+**Merged pull requests:**
+
+- fix: misspelled [\#31](https://github.com/DarkFlippers/flipperzero-subbrute/pull/31) ([derskythe](https://github.com/derskythe))
+- Improved extra settings [\#29](https://github.com/DarkFlippers/flipperzero-subbrute/pull/29) ([gid9798](https://github.com/gid9798))
+- сc1101 ext [\#28](https://github.com/DarkFlippers/flipperzero-subbrute/pull/28) ([gid9798](https://github.com/gid9798))
+- Feat/ci [\#26](https://github.com/DarkFlippers/flipperzero-subbrute/pull/26) ([derskythe](https://github.com/derskythe))
+- Sync [\#25](https://github.com/DarkFlippers/flipperzero-subbrute/pull/25) ([derskythe](https://github.com/derskythe))
+
+**Full Changelog**: [v3.2.3...v3.7.0](https://github.com/DarkFlippers/flipperzero-subbrute/compare/v3.2.3...v3.7.0)
+
+## [v3.2.3](https://github.com/DarkFlippers/flipperzero-subbrute/tree/v3.2.3) (2023-03-31)
+
+**Merged pull requests:**
+
+- Feat/ci [\#15](https://github.com/DarkFlippers/flipperzero-subbrute/pull/15) ([derskythe](https://github.com/derskythe))
+- Feat/ci [\#14](https://github.com/DarkFlippers/flipperzero-subbrute/pull/14) ([derskythe](https://github.com/derskythe))
+- Feat/ci [\#13](https://github.com/DarkFlippers/flipperzero-subbrute/pull/13) ([derskythe](https://github.com/derskythe))
+- Sync [\#12](https://github.com/DarkFlippers/flipperzero-subbrute/pull/12) ([derskythe](https://github.com/derskythe))
+- feat: ci was added [\#10](https://github.com/DarkFlippers/flipperzero-subbrute/pull/10) ([derskythe](https://github.com/derskythe))
+
+**Full Changelog**: [v3.2.1...v3.2.3](https://github.com/DarkFlippers/flipperzero-subbrute/compare/v3.2.1...v3.2.3)
+
+## [v3.2.1](https://github.com/DarkFlippers/flipperzero-subbrute/tree/v3.2.1) (2023-03-16)
+
+**Closed issues:**
+
+- Adding support for new protocol [\#9](https://github.com/DarkFlippers/flipperzero-subbrute/issues/9)
+- request: external cc1101 support [\#8](https://github.com/DarkFlippers/flipperzero-subbrute/issues/8)
+- brut 64 bit [\#6](https://github.com/DarkFlippers/flipperzero-subbrute/issues/6)
+
+**Merged pull requests:**
+
+- add honeywell protocol [\#4](https://github.com/DarkFlippers/flipperzero-subbrute/pull/4) ([s0u7f1r3](https://github.com/s0u7f1r3))
+- Feat/existing file two bytes [\#3](https://github.com/DarkFlippers/flipperzero-subbrute/pull/3) ([derskythe](https://github.com/derskythe))
+- Feat/more repeats [\#1](https://github.com/DarkFlippers/flipperzero-subbrute/pull/1) ([derskythe](https://github.com/derskythe))
+
+**Full Changelog**: [v3.1.0...v3.2.1](https://github.com/DarkFlippers/flipperzero-subbrute/compare/aa8001e6237804771738ce557039d1bf206aa7d1...v3.2.1)
+
+## [v3.1.1](https://github.com/DarkFlippers/flipperzero-subbrute/releases/tag/v3.1.1) (2022-10-23)
+
+Added Chamberlain 7bit 390MHz and Chamberlain 8bit 390MHz
+
+**Merged pull requests:**
+* Feat/more repeats by @derskythe in https://github.com/derskythe/flipperzero-subbrute/pull/1
+* Feat/existing file two bytes by @derskythe in https://github.com/derskythe/flipperzero-subbrute/pull/3
+* add honeywell protocol by @s0u7f1r3 in https://github.com/derskythe/flipperzero-subbrute/pull/4
+
+**New contributors**
+* @s0u7f1r3 made their first contribution in https://github.com/derskythe/flipperzero-subbrute/pull/4
+
+**Full Changelog**: [v3.1.0...3.1.1](https://github.com/DarkFlippers/flipperzero-subbrute/compare/v3.1.0...3.1.1)
+
+## [v3.1.0](https://github.com/DarkFlippers/flipperzero-subbrute/releases/tag/v3.1.0) (2022-10-22)
+
+**Full Changelog**: [v3.1.0...master](https://github.com/DarkFlippers/flipperzero-subbrute/compare/v3.1.0...master)

+ 21 - 0
subghz_bruteforcer/LICENSE

@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2023 DerSkythe
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.

+ 136 - 0
subghz_bruteforcer/README.md

@@ -0,0 +1,136 @@
+# SubGHz Bruteforcer Application for Flipper Zero
+
+![image](https://github.com/DarkFlippers/flipperzero-subbrute/assets/31771569/0a952559-94c0-40b7-8b9c-9ee4e37c6cd6)
+
+
+SubGhz Bruteforcer from [Unleashed Firmware](https://github.com/DarkFlippers/unleashed-firmware)
+
+## Disclaimer
+
+This software is for experimental purposes only and is not meant for any illegal activity/purposes.
+We do not condone illegal activity and strongly encourage keeping transmissions to legal/valid uses allowed by law.
+
+---
+
+## Installation
+
+The application is included in the standard firmware package of [Unleashed Firmware](https://github.com/DarkFlippers/unleashed-firmware). 
+You just need to install the [latest firmware](https://github.com/DarkFlippers/unleashed-firmware/releases/latest).
+<br />
+You can also download the [release](https://github.com/derskythe/flipperzero-subbrute/releases/latest) and unzip/untar it to the `SD Card/apps/Sub-GHz` directory.
+<br />
+> **Warning**
+> 
+> The application is not compatible with the official firmware version.
+> Also, it has not been tested on other firmware versions other than [Unleashed Firmware](https://github.com/DarkFlippers/unleashed-firmware) and [OFW](https://github.com/flipperdevices/flipperzero-firmware).
+
+## User Guide
+
+### Main Menu
+
+![image](https://github.com/DarkFlippers/flipperzero-subbrute/assets/31771569/9f428d6e-59fd-4517-895d-fb185f8d884f)
+
+Here you can select the protocol and frequency that will be used for bruteforce. 
+According to our observations, `CAME 12bit 433MHz` is the most protocol, so it is selected by default.
+To identify other devices and protocols, you should inspect the device.
+According to the protocol, when probe a key, each value is sent 3 times. 
+Most of the devices this works but there are devices that don't work and more repetitions are needed. 
+The number of repetitions can be increased with the right button, the left button decreases the value.
+The negative side of increasing the number of repetitions will be a longer key find time.
+
+![image](https://github.com/DarkFlippers/flipperzero-subbrute/assets/31771569/a17695d0-833d-44ce-a0d0-ead8366cb4fe)
+
+#### Buttons
+
+|           Button            |        Action         |
+|:---------------------------:|:---------------------:|
+|      :arrow_backward:       | Decrease repeat value |
+|      :arrow_up_small:       |        Move up        |
+|       :arrow_forward:       | Increase repeat value |
+|     :arrow_down_small:      |       Move down       |
+|       :record_button:       |    Select protocol    |
+| :leftwards_arrow_with_hook: |   Close application   |
+
+## Supported Protocols
+
+![image](https://github.com/DarkFlippers/flipperzero-subbrute/assets/31771569/1f14b5eb-7e66-4b37-b816-34fab63db70c)
+
+
+### CAME
+
+- CAME 12bit 303MHz
+- CAME 12bit 307MHz
+- CAME 12bit 315MHz
+- CAME 12bit 433MHz
+- CAME 12bit 868MHz
+
+### NICE
+
+- NICE 12bit 433MHz
+- NICE 12bit 868MHz
+
+### Ansonic
+
+- Ansonic 12bit 433.075MHz
+- Ansonic 12bit 433.920MHz
+- Ansonic 12bit 434.075MHz
+
+### Holtek
+
+- Holtek HT12X 12bit FM 433.920MHz (TE: 204μs)
+- Holtek HT12X 12bit AM 433.920MHz (TE: 433μs)
+- Holtek HT12X 12bit AM 315MHz (TE: 433μs)
+- Holtek HT12X 12bit AM 868MHz (TE: 433μs)
+- Holtek HT12X 12bit AM 915MHz (TE: 433μs)
+
+### Chamberlain
+
+- Chamberlain 9bit 300MHz
+- Chamberlain 9bit 315MHz
+- Chamberlain 9bit 390MHz
+- Chamberlain 9bit 433MHz
+- Chamberlain 8bit 300MHz
+- Chamberlain 8bit 315MHz
+- Chamberlain 8bit 390MHz
+- Chamberlain 7bit 300MHz
+- Chamberlain 7bit 315MHz
+- Chamberlain 7bit 390MHz
+
+### Linear
+
+- Linear 10bit 300MHz
+- Linear 10bit 310MHz
+- Linear Delta 3 8bit 310MHz
+
+### UNILARM
+
+> **Note**
+> 
+> Only dip switch combinations, not full 25bit bruteforce
+
+- UNILARM 25bit 330MHz (TE: 209μs)
+- UNILARM 25bit 433MHz (TE: 209μs)
+
+### SMC5326
+
+> **Note**
+> 
+> Only dip switch combinations, not full 25bit bruteforce
+
+- SMC5326 25bit 330MHz (TE: 320μs)
+- SMC5326 25bit 433MHz (TE: 320μs)
+
+### PT2260
+
+> **Note**
+> 
+> Only for 8 dip switch remote, not full 24bit bruteforce
+
+- PT2260 24bit 315MHz (TE: 286μs)
+- PT2260 24bit 330MHz (TE: 286μs)
+- PT2260 24bit 390MHz (TE: 286μs)
+- PT2260 24bit 433MHz (TE: 286μs)
+
+### Additional
+
+- BF Existing dump works for most other static protocols supported by Flipper Zero

+ 12 - 0
subghz_bruteforcer/application.fam

@@ -0,0 +1,12 @@
+App(
+    appid="subghz_bruteforcer",
+    name="Sub-GHz Bruteforcer",
+    apptype=FlipperAppType.EXTERNAL,
+    entry_point="subbrute_app",
+    requires=["gui","dialogs"],
+    stack_size=2 * 1024,
+    order=11,
+    fap_icon="subbrute_10px.png",
+    fap_category="Sub-GHz",
+    fap_icon_assets="images",
+)

+ 59 - 0
subghz_bruteforcer/helpers/gui_top_buttons.c

@@ -0,0 +1,59 @@
+#include "gui_top_buttons.h"
+
+void elements_button_top_left(Canvas* canvas, const char* str) {
+    const Icon* icon = &I_ButtonUp_7x4;
+
+    const uint8_t button_height = 12;
+    const uint8_t vertical_offset = 3;
+    const uint8_t horizontal_offset = 3;
+    const uint8_t string_width = canvas_string_width(canvas, str);
+    const uint8_t icon_h_offset = 3;
+    const uint8_t icon_width_with_offset = icon_get_width(icon) + icon_h_offset;
+    const uint8_t icon_v_offset = icon_get_height(icon) + vertical_offset;
+    const uint8_t button_width = string_width + horizontal_offset * 2 + icon_width_with_offset;
+
+    const uint8_t x = 0;
+    const uint8_t y = 0 + button_height;
+
+    uint8_t line_x = x + button_width;
+    uint8_t line_y = y - button_height;
+    canvas_draw_box(canvas, x, line_y, button_width, button_height);
+    canvas_draw_line(canvas, line_x + 0, line_y, line_x + 0, y - 1);
+    canvas_draw_line(canvas, line_x + 1, line_y, line_x + 1, y - 2);
+    canvas_draw_line(canvas, line_x + 2, line_y, line_x + 2, y - 3);
+
+    canvas_invert_color(canvas);
+    canvas_draw_icon(canvas, x + horizontal_offset, y - icon_v_offset, icon);
+    canvas_draw_str(
+        canvas, x + horizontal_offset + icon_width_with_offset, y - vertical_offset, str);
+    canvas_invert_color(canvas);
+}
+
+void elements_button_top_right(Canvas* canvas, const char* str) {
+    const Icon* icon = &I_ButtonDown_7x4;
+
+    const uint8_t button_height = 12;
+    const uint8_t vertical_offset = 3;
+    const uint8_t horizontal_offset = 3;
+    const uint8_t string_width = canvas_string_width(canvas, str);
+    const uint8_t icon_h_offset = 3;
+    const uint8_t icon_width_with_offset = icon_get_width(icon) + icon_h_offset;
+    const uint8_t icon_v_offset = icon_get_height(icon) + vertical_offset + 1;
+    const uint8_t button_width = string_width + horizontal_offset * 2 + icon_width_with_offset;
+
+    const uint8_t x = canvas_width(canvas);
+    const uint8_t y = 0 + button_height;
+
+    uint8_t line_x = x - button_width;
+    uint8_t line_y = y - button_height;
+    canvas_draw_box(canvas, line_x, line_y, button_width, button_height);
+    canvas_draw_line(canvas, line_x - 1, line_y, line_x - 1, y - 1);
+    canvas_draw_line(canvas, line_x - 2, line_y, line_x - 2, y - 2);
+    canvas_draw_line(canvas, line_x - 3, line_y, line_x - 3, y - 3);
+
+    canvas_invert_color(canvas);
+    canvas_draw_str(canvas, x - button_width + horizontal_offset, y - vertical_offset, str);
+    canvas_draw_icon(
+        canvas, x - horizontal_offset - icon_get_width(icon), y - icon_v_offset, icon);
+    canvas_invert_color(canvas);
+}

+ 23 - 0
subghz_bruteforcer/helpers/gui_top_buttons.h

@@ -0,0 +1,23 @@
+#pragma once
+
+#include <subghz_bruteforcer_icons.h>
+#include <input/input.h>
+#include <gui/elements.h>
+#include <gui/icon.h>
+#include <gui/icon_animation.h>
+
+#include <assets_icons.h>
+
+/**
+ * Thanks to the author of metronome
+ * @param canvas
+ * @param str
+ */
+void elements_button_top_left(Canvas* canvas, const char* str);
+
+/**
+ * Thanks to the author of metronome
+ * @param canvas
+ * @param str
+ */
+void elements_button_top_right(Canvas* canvas, const char* str);

+ 79 - 0
subghz_bruteforcer/helpers/subbrute_radio_device_loader.c

@@ -0,0 +1,79 @@
+#include <furi/core/check.h>
+
+#include <applications/drivers/subghz/cc1101_ext/cc1101_ext_interconnect.h>
+#include <lib/subghz/devices/cc1101_int/cc1101_int_interconnect.h>
+
+#include "subbrute_radio_device_loader.h"
+
+#define TAG "SubBruteRadioDeviceLoader"
+
+static void subbrute_radio_device_loader_power_on() {
+    uint8_t attempts = 5;
+    while(--attempts > 0) {
+        if(furi_hal_power_enable_otg()) {
+            break;
+        }
+    }
+    if(attempts == 0) {
+        if(furi_hal_power_get_usb_voltage() < 4.5f) {
+            FURI_LOG_E(
+                TAG,
+                "Error power otg enable. BQ2589 check otg fault = %d",
+                furi_hal_power_check_otg_fault() ? 1 : 0);
+        }
+    }
+}
+
+static void subbrute_radio_device_loader_power_off() {
+    if(furi_hal_power_is_otg_enabled()) {
+        furi_hal_power_disable_otg();
+    }
+}
+
+bool subbrute_radio_device_loader_is_connect_external(const char* name) {
+    bool is_connect = false;
+    bool is_otg_enabled = furi_hal_power_is_otg_enabled();
+
+    if(!is_otg_enabled) {
+        subbrute_radio_device_loader_power_on();
+    }
+
+    const SubGhzDevice* device = subghz_devices_get_by_name(name);
+    if(device) {
+        is_connect = subghz_devices_is_connect(device);
+    }
+
+    if(!is_otg_enabled) {
+        subbrute_radio_device_loader_power_off();
+    }
+    return is_connect;
+}
+
+const SubGhzDevice* subbrute_radio_device_loader_set(
+    const SubGhzDevice* current_radio_device,
+    SubGhzRadioDeviceType radio_device_type) {
+    const SubGhzDevice* radio_device;
+
+    if(radio_device_type == SubGhzRadioDeviceTypeExternalCC1101 &&
+       subbrute_radio_device_loader_is_connect_external(SUBGHZ_DEVICE_CC1101_EXT_NAME)) {
+        subbrute_radio_device_loader_power_on();
+        radio_device = subghz_devices_get_by_name(SUBGHZ_DEVICE_CC1101_EXT_NAME);
+        subghz_devices_begin(radio_device);
+    } else if(current_radio_device == NULL) {
+        radio_device = subghz_devices_get_by_name(SUBGHZ_DEVICE_CC1101_INT_NAME);
+    } else {
+        subbrute_radio_device_loader_end(current_radio_device);
+        radio_device = subghz_devices_get_by_name(SUBGHZ_DEVICE_CC1101_INT_NAME);
+    }
+
+    return radio_device;
+}
+
+void subbrute_radio_device_loader_end(const SubGhzDevice* radio_device) {
+    furi_assert(radio_device);
+
+    subbrute_radio_device_loader_power_off();
+    if(radio_device != subghz_devices_get_by_name(SUBGHZ_DEVICE_CC1101_INT_NAME)) {
+        subghz_devices_end(radio_device);
+    }
+}

+ 15 - 0
subghz_bruteforcer/helpers/subbrute_radio_device_loader.h

@@ -0,0 +1,15 @@
+#pragma once
+
+#include <lib/subghz/devices/devices.h>
+
+/** SubGhzRadioDeviceType */
+typedef enum {
+    SubGhzRadioDeviceTypeInternal,
+    SubGhzRadioDeviceTypeExternalCC1101,
+} SubGhzRadioDeviceType;
+
+const SubGhzDevice* subbrute_radio_device_loader_set(
+    const SubGhzDevice* current_radio_device,
+    SubGhzRadioDeviceType radio_device_type);
+
+void subbrute_radio_device_loader_end(const SubGhzDevice* radio_device);

+ 501 - 0
subghz_bruteforcer/helpers/subbrute_worker.c

@@ -0,0 +1,501 @@
+#include "subbrute_worker_private.h"
+#include <string.h>
+#include <toolbox/stream/stream.h>
+#include <flipper_format.h>
+#include <flipper_format_i.h>
+#include <lib/subghz/subghz_protocol_registry.h>
+
+#define TAG "SubBruteWorker"
+#define SUBBRUTE_TX_TIMEOUT 6
+#define SUBBRUTE_MANUAL_TRANSMIT_INTERVAL 250
+
+SubBruteWorker* subbrute_worker_alloc(const SubGhzDevice* radio_device) {
+    SubBruteWorker* instance = malloc(sizeof(SubBruteWorker));
+
+    instance->state = SubBruteWorkerStateIDLE;
+    instance->step = 0;
+    instance->worker_running = false;
+    instance->initiated = false;
+    instance->last_time_tx_data = 0;
+    instance->load_index = 0;
+
+    instance->thread = furi_thread_alloc();
+    furi_thread_set_name(instance->thread, "SubBruteAttackWorker");
+    furi_thread_set_stack_size(instance->thread, 2048);
+    furi_thread_set_context(instance->thread, instance);
+    furi_thread_set_callback(instance->thread, subbrute_worker_thread);
+
+    instance->context = NULL;
+    instance->callback = NULL;
+
+    instance->tx_timeout_ms = SUBBRUTE_TX_TIMEOUT;
+    instance->decoder_result = NULL;
+    instance->transmitter = NULL;
+    instance->environment = subghz_environment_alloc();
+    subghz_environment_set_protocol_registry(
+        instance->environment, (void*)&subghz_protocol_registry);
+
+    instance->transmit_mode = false;
+
+    instance->radio_device = radio_device;
+
+    return instance;
+}
+
+void subbrute_worker_free(SubBruteWorker* instance) {
+    furi_assert(instance);
+
+    // I don't know how to free this
+    instance->decoder_result = NULL;
+
+    if(instance->transmitter != NULL) {
+        subghz_transmitter_free(instance->transmitter);
+        instance->transmitter = NULL;
+    }
+
+    subghz_environment_free(instance->environment);
+    instance->environment = NULL;
+
+    furi_thread_free(instance->thread);
+
+    subghz_devices_sleep(instance->radio_device);
+    subbrute_radio_device_loader_end(instance->radio_device);
+
+    free(instance);
+}
+
+uint64_t subbrute_worker_get_step(SubBruteWorker* instance) {
+    return instance->step;
+}
+
+bool subbrute_worker_set_step(SubBruteWorker* instance, uint64_t step) {
+    furi_assert(instance);
+    if(!subbrute_worker_can_manual_transmit(instance)) {
+        FURI_LOG_W(TAG, "Cannot set step during running mode");
+        return false;
+    }
+
+    instance->step = step;
+
+    return true;
+}
+
+bool subbrute_worker_init_default_attack(
+    SubBruteWorker* instance,
+    SubBruteAttacks attack_type,
+    uint64_t step,
+    const SubBruteProtocol* protocol,
+    uint8_t repeats) {
+    furi_assert(instance);
+
+    if(instance->worker_running) {
+        FURI_LOG_W(TAG, "Init Worker when it's running");
+        subbrute_worker_stop(instance);
+    }
+
+    instance->attack = attack_type;
+    instance->frequency = protocol->frequency;
+    instance->preset = protocol->preset;
+    instance->file = protocol->file;
+    instance->step = step;
+    instance->bits = protocol->bits;
+    instance->te = protocol->te;
+    instance->repeat = repeats;
+    instance->load_index = 0;
+    instance->file_key = 0;
+    instance->two_bytes = false;
+
+    instance->max_value =
+        subbrute_protocol_calc_max_value(instance->attack, instance->bits, instance->two_bytes);
+
+    instance->initiated = true;
+    instance->state = SubBruteWorkerStateReady;
+    subbrute_worker_send_callback(instance);
+#ifdef FURI_DEBUG
+    FURI_LOG_I(
+        TAG,
+        "subbrute_worker_init_default_attack: %s, bits: %d, preset: %s, file: %s, te: %ld, repeat: %d, max_value: %lld",
+        subbrute_protocol_name(instance->attack),
+        instance->bits,
+        subbrute_protocol_preset(instance->preset),
+        subbrute_protocol_file(instance->file),
+        instance->te,
+        instance->repeat,
+        instance->max_value);
+#endif
+
+    return true;
+}
+
+bool subbrute_worker_init_file_attack(
+    SubBruteWorker* instance,
+    uint64_t step,
+    uint8_t load_index,
+    uint64_t file_key,
+    SubBruteProtocol* protocol,
+    uint8_t repeats,
+    bool two_bytes) {
+    furi_assert(instance);
+
+    if(instance->worker_running) {
+        FURI_LOG_W(TAG, "Init Worker when it's running");
+        subbrute_worker_stop(instance);
+    }
+
+    instance->attack = SubBruteAttackLoadFile;
+    instance->frequency = protocol->frequency;
+    instance->preset = protocol->preset;
+    instance->file = protocol->file;
+    instance->step = step;
+    instance->bits = protocol->bits;
+    instance->te = protocol->te;
+    instance->load_index = load_index;
+    instance->repeat = repeats;
+    instance->file_key = file_key;
+    instance->two_bytes = two_bytes;
+
+    instance->max_value =
+        subbrute_protocol_calc_max_value(instance->attack, instance->bits, instance->two_bytes);
+
+    instance->initiated = true;
+    instance->state = SubBruteWorkerStateReady;
+    subbrute_worker_send_callback(instance);
+#ifdef FURI_DEBUG
+    FURI_LOG_I(
+        TAG,
+        "subbrute_worker_init_file_attack: %s, bits: %d, preset: %s, file: %s, te: %ld, repeat: %d, max_value: %lld, key: %llX",
+        subbrute_protocol_name(instance->attack),
+        instance->bits,
+        subbrute_protocol_preset(instance->preset),
+        subbrute_protocol_file(instance->file),
+        instance->te,
+        instance->repeat,
+        instance->max_value,
+        instance->file_key);
+#endif
+
+    return true;
+}
+
+bool subbrute_worker_start(SubBruteWorker* instance) {
+    furi_assert(instance);
+
+    if(!instance->initiated) {
+        FURI_LOG_W(TAG, "Worker not init!");
+        return false;
+    }
+
+    if(instance->worker_running) {
+        FURI_LOG_W(TAG, "Worker is already running!");
+        return false;
+    }
+    if(instance->state != SubBruteWorkerStateReady &&
+       instance->state != SubBruteWorkerStateFinished) {
+        FURI_LOG_W(TAG, "Worker cannot start, invalid device state: %d", instance->state);
+        return false;
+    }
+
+    instance->worker_running = true;
+    furi_thread_start(instance->thread);
+
+    return true;
+}
+
+void subbrute_worker_stop(SubBruteWorker* instance) {
+    furi_assert(instance);
+
+    if(!instance->worker_running) {
+        return;
+    }
+
+    instance->worker_running = false;
+    furi_thread_join(instance->thread);
+
+    subghz_devices_idle(instance->radio_device);
+}
+
+bool subbrute_worker_transmit_current_key(SubBruteWorker* instance, uint64_t step) {
+    furi_assert(instance);
+
+    if(!instance->initiated) {
+        FURI_LOG_W(TAG, "Worker not init!");
+        return false;
+    }
+    if(instance->worker_running) {
+        FURI_LOG_W(TAG, "Worker in running state!");
+        return false;
+    }
+    if(instance->state != SubBruteWorkerStateReady &&
+       instance->state != SubBruteWorkerStateFinished) {
+        FURI_LOG_W(TAG, "Invalid state for running worker! State: %d", instance->state);
+        return false;
+    }
+
+    uint32_t ticks = furi_get_tick();
+    if((ticks - instance->last_time_tx_data) < SUBBRUTE_MANUAL_TRANSMIT_INTERVAL) {
+#if FURI_DEBUG
+        FURI_LOG_D(TAG, "Need to wait, current: %ld", ticks - instance->last_time_tx_data);
+#endif
+        return false;
+    }
+
+    instance->last_time_tx_data = ticks;
+    instance->step = step;
+
+    bool result;
+    instance->protocol_name = subbrute_protocol_file(instance->file);
+    FlipperFormat* flipper_format = flipper_format_string_alloc();
+    Stream* stream = flipper_format_get_raw_stream(flipper_format);
+
+    stream_clean(stream);
+
+    if(instance->attack == SubBruteAttackLoadFile) {
+        subbrute_protocol_file_payload(
+            stream,
+            step,
+            instance->bits,
+            instance->te,
+            instance->repeat,
+            instance->load_index,
+            instance->file_key,
+            instance->two_bytes);
+    } else {
+        subbrute_protocol_default_payload(
+            stream, instance->file, step, instance->bits, instance->te, instance->repeat);
+    }
+
+    //    size_t written = stream_write_string(stream, payload);
+    //    if(written <= 0) {
+    //        FURI_LOG_W(TAG, "Error creating packet! EXIT");
+    //        result = false;
+    //    } else {
+    subbrute_worker_subghz_transmit(instance, flipper_format);
+
+    result = true;
+#if FURI_DEBUG
+    FURI_LOG_D(TAG, "Manual transmit done");
+#endif
+    //    }
+
+    flipper_format_free(flipper_format);
+    //    furi_string_free(payload);
+
+    return result;
+}
+
+bool subbrute_worker_is_running(SubBruteWorker* instance) {
+    return instance->worker_running;
+}
+
+bool subbrute_worker_can_manual_transmit(SubBruteWorker* instance) {
+    furi_assert(instance);
+
+    if(!instance->initiated) {
+        FURI_LOG_W(TAG, "Worker not init!");
+        return false;
+    }
+
+    return !instance->worker_running && instance->state != SubBruteWorkerStateIDLE &&
+           instance->state != SubBruteWorkerStateTx &&
+           ((furi_get_tick() - instance->last_time_tx_data) > SUBBRUTE_MANUAL_TRANSMIT_INTERVAL);
+}
+
+void subbrute_worker_set_callback(
+    SubBruteWorker* instance,
+    SubBruteWorkerCallback callback,
+    void* context) {
+    furi_assert(instance);
+
+    instance->callback = callback;
+    instance->context = context;
+}
+
+void subbrute_worker_subghz_transmit(SubBruteWorker* instance, FlipperFormat* flipper_format) {
+    const uint8_t timeout = instance->tx_timeout_ms;
+    while(instance->transmit_mode) {
+        furi_delay_ms(timeout);
+    }
+    instance->transmit_mode = true;
+    if(instance->transmitter != NULL) {
+        subghz_transmitter_free(instance->transmitter);
+        instance->transmitter = NULL;
+    }
+    instance->transmitter =
+        subghz_transmitter_alloc_init(instance->environment, instance->protocol_name);
+    subghz_transmitter_deserialize(instance->transmitter, flipper_format);
+
+    subghz_devices_reset(instance->radio_device);
+    subghz_devices_idle(instance->radio_device);
+    subghz_devices_load_preset(instance->radio_device, instance->preset, NULL);
+    subghz_devices_set_frequency(
+        instance->radio_device, instance->frequency); // TODO is freq valid check
+
+    if(subghz_devices_set_tx(instance->radio_device)) {
+        subghz_devices_start_async_tx(
+            instance->radio_device, subghz_transmitter_yield, instance->transmitter);
+        while(!subghz_devices_is_async_complete_tx(instance->radio_device)) {
+            furi_delay_ms(timeout);
+        }
+        subghz_devices_stop_async_tx(instance->radio_device);
+    }
+
+    subghz_devices_idle(instance->radio_device);
+
+    subghz_transmitter_stop(instance->transmitter);
+    subghz_transmitter_free(instance->transmitter);
+    instance->transmitter = NULL;
+
+    instance->transmit_mode = false;
+}
+
+void subbrute_worker_send_callback(SubBruteWorker* instance) {
+    if(instance->callback != NULL) {
+        instance->callback(instance->context, instance->state);
+    }
+}
+
+/**
+ * Entrypoint for worker
+ *
+ * @param context SubBruteWorker*
+ * @return 0 if ok
+ */
+int32_t subbrute_worker_thread(void* context) {
+    furi_assert(context);
+    SubBruteWorker* instance = (SubBruteWorker*)context;
+
+    if(!instance->worker_running) {
+        FURI_LOG_W(TAG, "Worker is not set to running state!");
+        return -1;
+    }
+    if(instance->state != SubBruteWorkerStateReady &&
+       instance->state != SubBruteWorkerStateFinished) {
+        FURI_LOG_W(TAG, "Invalid state for running worker! State: %d", instance->state);
+        return -2;
+    }
+#ifdef FURI_DEBUG
+    FURI_LOG_I(TAG, "Worker start");
+#endif
+
+    SubBruteWorkerState local_state = instance->state = SubBruteWorkerStateTx;
+    subbrute_worker_send_callback(instance);
+
+    instance->protocol_name = subbrute_protocol_file(instance->file);
+
+    FlipperFormat* flipper_format = flipper_format_string_alloc();
+    Stream* stream = flipper_format_get_raw_stream(flipper_format);
+
+    while(instance->worker_running) {
+        stream_clean(stream);
+        if(instance->attack == SubBruteAttackLoadFile) {
+            subbrute_protocol_file_payload(
+                stream,
+                instance->step,
+                instance->bits,
+                instance->te,
+                instance->repeat,
+                instance->load_index,
+                instance->file_key,
+                instance->two_bytes);
+        } else {
+            subbrute_protocol_default_payload(
+                stream,
+                instance->file,
+                instance->step,
+                instance->bits,
+                instance->te,
+                instance->repeat);
+        }
+#ifdef FURI_DEBUG
+        //FURI_LOG_I(TAG, "Payload: %s", furi_string_get_cstr(payload));
+        //furi_delay_ms(SUBBRUTE_MANUAL_TRANSMIT_INTERVAL / 4);
+#endif
+
+        //        size_t written = stream_write_stream_write_string(stream, payload);
+        //        if(written <= 0) {
+        //            FURI_LOG_W(TAG, "Error creating packet! BREAK");
+        //            instance->worker_running = false;
+        //            local_state = SubBruteWorkerStateIDLE;
+        //            furi_string_free(payload);
+        //            break;
+        //        }
+
+        subbrute_worker_subghz_transmit(instance, flipper_format);
+
+        if(instance->step + 1 > instance->max_value) {
+#ifdef FURI_DEBUG
+            FURI_LOG_I(TAG, "Worker finished to end");
+#endif
+            local_state = SubBruteWorkerStateFinished;
+            //            furi_string_free(payload);
+            break;
+        }
+        instance->step++;
+
+        //        furi_string_free(payload);
+        furi_delay_ms(instance->tx_timeout_ms);
+    }
+
+    flipper_format_free(flipper_format);
+
+    instance->worker_running = false; // Because we have error states
+    instance->state = local_state == SubBruteWorkerStateTx ? SubBruteWorkerStateReady :
+                                                             local_state;
+    subbrute_worker_send_callback(instance);
+
+#ifdef FURI_DEBUG
+    FURI_LOG_I(TAG, "Worker stop");
+#endif
+    return 0;
+}
+
+uint8_t subbrute_worker_get_timeout(SubBruteWorker* instance) {
+    return instance->tx_timeout_ms;
+}
+
+void subbrute_worker_set_timeout(SubBruteWorker* instance, uint8_t timeout) {
+    instance->tx_timeout_ms = timeout;
+}
+
+uint8_t subbrute_worker_get_repeats(SubBruteWorker* instance) {
+    return instance->repeat;
+}
+
+void subbrute_worker_set_repeats(SubBruteWorker* instance, uint8_t repeats) {
+    instance->repeat = repeats;
+}
+
+uint32_t subbrute_worker_get_te(SubBruteWorker* instance) {
+    return instance->te;
+}
+
+void subbrute_worker_set_te(SubBruteWorker* instance, uint32_t te) {
+    instance->te = te;
+}
+
+// void subbrute_worker_timeout_inc(SubBruteWorker* instance) {
+//     if(instance->tx_timeout_ms < 255) {
+//         instance->tx_timeout_ms++;
+//     }
+// }
+
+// void subbrute_worker_timeout_dec(SubBruteWorker* instance) {
+//     if(instance->tx_timeout_ms > 0) {
+//         instance->tx_timeout_ms--;
+//     }
+// }
+
+bool subbrute_worker_is_tx_allowed(SubBruteWorker* instance, uint32_t value) {
+    furi_assert(instance);
+    bool res = false;
+
+    if(!subghz_devices_is_frequency_valid(instance->radio_device, value)) {
+        return false;
+    } else {
+        subghz_devices_set_frequency(instance->radio_device, value);
+        res = subghz_devices_set_tx(instance->radio_device);
+        subghz_devices_idle(instance->radio_device);
+    }
+
+    return res;
+}

+ 56 - 0
subghz_bruteforcer/helpers/subbrute_worker.h

@@ -0,0 +1,56 @@
+#pragma once
+
+#include "../subbrute_protocols.h"
+#include "subbrute_radio_device_loader.h"
+
+typedef enum {
+    SubBruteWorkerStateIDLE,
+    SubBruteWorkerStateReady,
+    SubBruteWorkerStateTx,
+    SubBruteWorkerStateFinished
+} SubBruteWorkerState;
+
+typedef void (*SubBruteWorkerCallback)(void* context, SubBruteWorkerState state);
+
+typedef struct SubBruteWorker SubBruteWorker;
+
+SubBruteWorker* subbrute_worker_alloc(const SubGhzDevice* radio_device);
+void subbrute_worker_free(SubBruteWorker* instance);
+uint64_t subbrute_worker_get_step(SubBruteWorker* instance);
+bool subbrute_worker_set_step(SubBruteWorker* instance, uint64_t step);
+bool subbrute_worker_is_running(SubBruteWorker* instance);
+bool subbrute_worker_init_default_attack(
+    SubBruteWorker* instance,
+    SubBruteAttacks attack_type,
+    uint64_t step,
+    const SubBruteProtocol* protocol,
+    uint8_t repeats);
+bool subbrute_worker_init_file_attack(
+    SubBruteWorker* instance,
+    uint64_t step,
+    uint8_t load_index,
+    uint64_t file_key,
+    SubBruteProtocol* protocol,
+    uint8_t repeats,
+    bool two_bytes);
+bool subbrute_worker_start(SubBruteWorker* instance);
+void subbrute_worker_stop(SubBruteWorker* instance);
+bool subbrute_worker_transmit_current_key(SubBruteWorker* instance, uint64_t step);
+bool subbrute_worker_can_manual_transmit(SubBruteWorker* instance);
+void subbrute_worker_set_callback(
+    SubBruteWorker* instance,
+    SubBruteWorkerCallback callback,
+    void* context);
+
+uint8_t subbrute_worker_get_timeout(SubBruteWorker* instance);
+void subbrute_worker_set_timeout(SubBruteWorker* instance, uint8_t timeout);
+uint8_t subbrute_worker_get_repeats(SubBruteWorker* instance);
+void subbrute_worker_set_repeats(SubBruteWorker* instance, uint8_t repeats);
+uint32_t subbrute_worker_get_te(SubBruteWorker* instance);
+void subbrute_worker_set_te(SubBruteWorker* instance, uint32_t te);
+
+// void subbrute_worker_timeout_inc(SubBruteWorker* instance);
+
+// void subbrute_worker_timeout_dec(SubBruteWorker* instance);
+
+bool subbrute_worker_is_tx_allowed(SubBruteWorker* instance, uint32_t value);

+ 50 - 0
subghz_bruteforcer/helpers/subbrute_worker_private.h

@@ -0,0 +1,50 @@
+#pragma once
+
+#include "subbrute_worker.h"
+#include <lib/subghz/protocols/base.h>
+#include <lib/subghz/transmitter.h>
+#include <lib/subghz/receiver.h>
+#include <lib/subghz/environment.h>
+
+struct SubBruteWorker {
+    SubBruteWorkerState state;
+    volatile bool worker_running;
+    volatile bool initiated;
+    volatile bool transmit_mode;
+
+    // Current step
+    uint64_t step;
+
+    // SubGhz
+    FuriThread* thread;
+    SubGhzProtocolDecoderBase* decoder_result;
+    SubGhzEnvironment* environment;
+    SubGhzTransmitter* transmitter;
+    const char* protocol_name;
+    uint8_t tx_timeout_ms;
+    const SubGhzDevice* radio_device;
+
+    // Initiated values
+    SubBruteAttacks attack; // Attack state
+    uint32_t frequency;
+    FuriHalSubGhzPreset preset;
+    SubBruteFileProtocol file;
+    uint8_t bits;
+    uint32_t te;
+    uint8_t repeat;
+    uint8_t load_index; // Index of group to bruteforce in loaded file
+    uint64_t file_key;
+    uint64_t max_value; // Max step
+    bool two_bytes;
+
+    // Manual transmit
+    uint32_t last_time_tx_data;
+
+    // Callback for changed states
+    SubBruteWorkerCallback callback;
+    void* context;
+};
+
+int32_t subbrute_worker_thread(void* context);
+void subbrute_worker_subghz_transmit(SubBruteWorker* instance, FlipperFormat* flipper_format);
+void subbrute_worker_send_callback(SubBruteWorker* instance);

+ 15 - 0
subghz_bruteforcer/manifest.yml

@@ -0,0 +1,15 @@
+sourcecode:
+  type: git
+  location:
+    origin: https://github.com/derskythe/flipperzero-subbrute
+    commit_sha: 7666ee61a5c4f3a85dd0eded24c2e73b2f5bc4a9
+    subdir: subbrute
+description: "@README.md"
+changelog: "v3.8.0 - OFW SDK support"
+author: "@DerSkythe @xMasterX @gid9798"
+screenshots:
+  - "screenshots/screenshot_01.png"
+  - "screenshots/screenshot_02.png"
+  - "screenshots/screenshot_03.png"
+  - "screenshots/screenshot_04.png"
+  - "screenshots/screenshot_05.png"

+ 29 - 0
subghz_bruteforcer/scenes/subbrute_scene.h

@@ -0,0 +1,29 @@
+#pragma once
+
+#include <gui/scene_manager.h>
+
+// Generate scene id and total number
+#define ADD_SCENE(prefix, name, id) SubBruteScene##id,
+typedef enum {
+#include "subbrute_scene_config.h"
+    SubBruteSceneNum,
+} SubBruteScene;
+#undef ADD_SCENE
+
+extern const SceneManagerHandlers subbrute_scene_handlers;
+
+// Generate scene on_enter handlers declaration
+#define ADD_SCENE(prefix, name, id) void prefix##_scene_##name##_on_enter(void*);
+#include "subbrute_scene_config.h"
+#undef ADD_SCENE
+
+// Generate scene on_event handlers declaration
+#define ADD_SCENE(prefix, name, id) \
+    bool prefix##_scene_##name##_on_event(void* context, SceneManagerEvent event);
+#include "subbrute_scene_config.h"
+#undef ADD_SCENE
+
+// Generate scene on_exit handlers declaration
+#define ADD_SCENE(prefix, name, id) void prefix##_scene_##name##_on_exit(void* context);
+#include "subbrute_scene_config.h"
+#undef ADD_SCENE

+ 8 - 0
subghz_bruteforcer/scenes/subbrute_scene_config.h

@@ -0,0 +1,8 @@
+ADD_SCENE(subbrute, load_file, LoadFile)
+ADD_SCENE(subbrute, load_select, LoadSelect)
+ADD_SCENE(subbrute, run_attack, RunAttack)
+ADD_SCENE(subbrute, save_name, SaveName)
+ADD_SCENE(subbrute, save_success, SaveSuccess)
+ADD_SCENE(subbrute, setup_attack, SetupAttack)
+ADD_SCENE(subbrute, setup_extra, SetupExtra)
+ADD_SCENE(subbrute, start, Start)

+ 95 - 0
subghz_bruteforcer/scenes/subbrute_scene_load_file.c

@@ -0,0 +1,95 @@
+#include "../subbrute_i.h"
+#include "subbrute_scene.h"
+
+#define TAG "SubBruteSceneLoadFile"
+
+void subbrute_scene_load_file_on_enter(void* context) {
+    furi_assert(context);
+    SubBruteState* instance = (SubBruteState*)context;
+
+    // Input events and views are managed by file_browser
+    FuriString* app_folder;
+    FuriString* load_path;
+    load_path = furi_string_alloc();
+    app_folder = furi_string_alloc_set(SUBBRUTE_PATH);
+
+    DialogsFileBrowserOptions browser_options;
+    dialog_file_browser_set_basic_options(&browser_options, SUBBRUTE_FILE_EXT, &I_sub1_10px);
+
+    SubBruteFileResult load_result;
+    // TODO: DELETE IT
+#ifdef SUBBRUTE_FAST_TRACK
+    bool res = true;
+    furi_string_printf(load_path, "%s", "/ext/subghz/princeton.sub");
+#else
+    bool res =
+        dialog_file_browser_show(instance->dialogs, load_path, app_folder, &browser_options);
+#endif
+#ifdef FURI_DEBUG
+    FURI_LOG_D(
+        TAG,
+        "load_path: %s, app_folder: %s",
+        furi_string_get_cstr(load_path),
+        furi_string_get_cstr(app_folder));
+#endif
+    if(res) {
+        load_result =
+            subbrute_device_load_from_file(instance->device, furi_string_get_cstr(load_path));
+        if(load_result == SubBruteFileResultOk) {
+            instance->settings->last_index = SubBruteAttackLoadFile;
+            subbrute_settings_set_repeats(
+                instance->settings, subbrute_main_view_get_repeats(instance->view_main));
+            uint8_t extra_repeats = subbrute_settings_get_current_repeats(instance->settings);
+
+            load_result = subbrute_device_attack_set(
+                instance->device, instance->settings->last_index, extra_repeats);
+            if(load_result == SubBruteFileResultOk) {
+                if(!subbrute_worker_init_file_attack(
+                       instance->worker,
+                       instance->device->current_step,
+                       instance->device->bit_index,
+                       instance->device->key_from_file,
+                       instance->device->file_protocol_info,
+                       extra_repeats,
+                       instance->device->two_bytes)) {
+                    furi_crash("Invalid attack set!");
+                }
+                // Ready to run!
+                FURI_LOG_I(TAG, "Ready to run");
+                res = true;
+            }
+        }
+
+        if(load_result == SubBruteFileResultOk) {
+            subbrute_settings_save(instance->settings);
+            scene_manager_next_scene(instance->scene_manager, SubBruteSceneLoadSelect);
+        } else {
+            FURI_LOG_E(TAG, "Returned error: %d", load_result);
+
+            FuriString* dialog_msg;
+            dialog_msg = furi_string_alloc();
+            furi_string_cat_printf(
+                dialog_msg, "Cannot parse\nfile: %s", subbrute_device_error_get_desc(load_result));
+            dialog_message_show_storage_error(instance->dialogs, furi_string_get_cstr(dialog_msg));
+            furi_string_free(dialog_msg);
+            scene_manager_search_and_switch_to_previous_scene(
+                instance->scene_manager, SubBruteSceneStart);
+        }
+    } else {
+        scene_manager_search_and_switch_to_previous_scene(
+            instance->scene_manager, SubBruteSceneStart);
+    }
+
+    furi_string_free(app_folder);
+    furi_string_free(load_path);
+}
+
+void subbrute_scene_load_file_on_exit(void* context) {
+    UNUSED(context);
+}
+
+bool subbrute_scene_load_file_on_event(void* context, SceneManagerEvent event) {
+    UNUSED(context);
+    UNUSED(event);
+    return false;
+}

+ 93 - 0
subghz_bruteforcer/scenes/subbrute_scene_load_select.c

@@ -0,0 +1,93 @@
+#include "../subbrute_i.h"
+#include "subbrute_scene.h"
+
+#define TAG "SubBruteSceneStart"
+
+void subbrute_scene_load_select_callback(SubBruteCustomEvent event, void* context) {
+    furi_assert(context);
+
+    SubBruteState* instance = (SubBruteState*)context;
+    view_dispatcher_send_custom_event(instance->view_dispatcher, event);
+}
+
+void subbrute_scene_load_select_on_enter(void* context) {
+    furi_assert(context);
+#ifdef FURI_DEBUG
+    FURI_LOG_I(TAG, "subbrute_scene_load_select_on_enter");
+#endif
+    SubBruteState* instance = (SubBruteState*)context;
+    SubBruteMainView* view = instance->view_main;
+
+    instance->current_view = SubBruteViewMain;
+    subbrute_main_view_set_callback(view, subbrute_scene_load_select_callback, instance);
+    subbrute_main_view_set_index(
+        view,
+        7,
+        instance->settings->repeat_values,
+        true,
+        instance->device->two_bytes,
+        instance->device->key_from_file);
+
+    view_dispatcher_switch_to_view(instance->view_dispatcher, instance->current_view);
+}
+
+void subbrute_scene_load_select_on_exit(void* context) {
+    UNUSED(context);
+#ifdef FURI_DEBUG
+    FURI_LOG_I(TAG, "subbrute_scene_load_select_on_exit");
+#endif
+}
+
+bool subbrute_scene_load_select_on_event(void* context, SceneManagerEvent event) {
+    SubBruteState* instance = (SubBruteState*)context;
+    bool consumed = false;
+
+    if(event.type == SceneManagerEventTypeCustom) {
+        if(event.event == SubBruteCustomEventTypeIndexSelected) {
+            /*#ifdef FURI_DEBUG && !SUBBRUTE_FAST_TRACK
+            view_dispatcher_stop(instance->view_dispatcher);
+            consumed = true;
+#else*/
+            instance->device->current_step = 0;
+            instance->device->bit_index = subbrute_main_view_get_index(instance->view_main);
+            instance->device->two_bytes = subbrute_main_view_get_two_bytes(instance->view_main);
+
+            instance->settings->last_index = instance->device->attack;
+            subbrute_settings_set_repeats(
+                instance->settings, subbrute_main_view_get_repeats(instance->view_main));
+            uint8_t total_repeats = subbrute_settings_get_current_repeats(instance->settings);
+
+            instance->device->max_value = subbrute_protocol_calc_max_value(
+                instance->device->attack,
+                instance->device->bit_index,
+                instance->device->two_bytes);
+
+            if(!subbrute_worker_init_file_attack(
+                   instance->worker,
+                   instance->device->current_step,
+                   instance->device->bit_index,
+                   instance->device->key_from_file,
+                   instance->device->file_protocol_info,
+                   total_repeats,
+                   instance->device->two_bytes)) {
+                furi_crash("Invalid attack set!");
+            }
+            subbrute_settings_save(instance->settings);
+            scene_manager_next_scene(instance->scene_manager, SubBruteSceneSetupAttack);
+            /*#endif*/
+            consumed = true;
+        } /* else if(event.event == SubBruteCustomEventTypeChangeStepUp) {
+            instance->device->two_bytes = true;
+        } else if(event.event == SubBruteCustomEventTypeChangeStepDown) {
+            instance->device->two_bytes = false;
+        }*/
+    } else if(event.type == SceneManagerEventTypeBack) {
+        if(!scene_manager_search_and_switch_to_previous_scene(
+               instance->scene_manager, SubBruteSceneStart)) {
+            scene_manager_next_scene(instance->scene_manager, SubBruteSceneStart);
+        }
+        consumed = true;
+    }
+
+    return consumed;
+}

+ 104 - 0
subghz_bruteforcer/scenes/subbrute_scene_run_attack.c

@@ -0,0 +1,104 @@
+#include "../subbrute_i.h"
+#include "subbrute_scene.h"
+
+#define TAG "SubBruteSceneRunAttack"
+
+static void subbrute_scene_run_attack_callback(SubBruteCustomEvent event, void* context) {
+    furi_assert(context);
+
+    SubBruteState* instance = (SubBruteState*)context;
+    view_dispatcher_send_custom_event(instance->view_dispatcher, event);
+}
+
+static void
+    subbrute_scene_run_attack_device_state_changed(void* context, SubBruteWorkerState state) {
+    furi_assert(context);
+
+    SubBruteState* instance = (SubBruteState*)context;
+
+    if(state == SubBruteWorkerStateIDLE) {
+        // Can't be IDLE on this step!
+        view_dispatcher_send_custom_event(instance->view_dispatcher, SubBruteCustomEventTypeError);
+    } else if(state == SubBruteWorkerStateFinished) {
+        view_dispatcher_send_custom_event(
+            instance->view_dispatcher, SubBruteCustomEventTypeTransmitFinished);
+    }
+}
+void subbrute_scene_run_attack_on_exit(void* context) {
+    furi_assert(context);
+    SubBruteState* instance = (SubBruteState*)context;
+
+    notification_message(instance->notifications, &sequence_blink_stop);
+    subbrute_worker_stop(instance->worker);
+}
+
+void subbrute_scene_run_attack_on_enter(void* context) {
+    furi_assert(context);
+    SubBruteState* instance = (SubBruteState*)context;
+    SubBruteAttackView* view = instance->view_attack;
+
+    instance->current_view = SubBruteViewAttack;
+    subbrute_attack_view_set_callback(view, subbrute_scene_run_attack_callback, instance);
+    view_dispatcher_switch_to_view(instance->view_dispatcher, instance->current_view);
+
+    subbrute_worker_set_callback(
+        instance->worker, subbrute_scene_run_attack_device_state_changed, instance);
+
+    if(!subbrute_worker_is_running(instance->worker)) {
+        subbrute_worker_set_step(instance->worker, instance->device->current_step);
+        if(!subbrute_worker_start(instance->worker)) {
+            view_dispatcher_send_custom_event(
+                instance->view_dispatcher, SubBruteCustomEventTypeError);
+        } else {
+            notification_message(instance->notifications, &sequence_single_vibro);
+            notification_message(instance->notifications, &sequence_blink_start_yellow);
+        }
+    }
+}
+
+bool subbrute_scene_run_attack_on_event(void* context, SceneManagerEvent event) {
+    SubBruteState* instance = (SubBruteState*)context;
+    SubBruteAttackView* view = instance->view_attack;
+
+    bool consumed = false;
+
+    if(event.type == SceneManagerEventTypeCustom) {
+        uint64_t step = subbrute_worker_get_step(instance->worker);
+        instance->device->current_step = step;
+        subbrute_attack_view_set_current_step(view, step);
+
+        if(event.event == SubBruteCustomEventTypeTransmitFinished) {
+            notification_message(instance->notifications, &sequence_display_backlight_on);
+            notification_message(instance->notifications, &sequence_double_vibro);
+
+            scene_manager_next_scene(instance->scene_manager, SubBruteSceneSetupAttack);
+        } else if(
+            event.event == SubBruteCustomEventTypeTransmitNotStarted ||
+            event.event == SubBruteCustomEventTypeBackPressed) {
+            if(subbrute_worker_is_running(instance->worker)) {
+                // Notify
+                notification_message(instance->notifications, &sequence_single_vibro);
+            }
+            // Stop transmit
+            scene_manager_search_and_switch_to_previous_scene(
+                instance->scene_manager, SubBruteSceneSetupAttack);
+        } else if(event.event == SubBruteCustomEventTypeError) {
+            notification_message(instance->notifications, &sequence_error);
+
+            // Stop transmit
+            scene_manager_search_and_switch_to_previous_scene(
+                instance->scene_manager, SubBruteSceneSetupAttack);
+        } else if(event.event == SubBruteCustomEventTypeUpdateView) {
+            //subbrute_attack_view_set_current_step(view, instance->device->current_step);
+        }
+        consumed = true;
+    } else if(event.type == SceneManagerEventTypeTick) {
+        uint64_t step = subbrute_worker_get_step(instance->worker);
+        instance->device->current_step = step;
+        subbrute_attack_view_set_current_step(view, step);
+
+        consumed = true;
+    }
+
+    return consumed;
+}

+ 87 - 0
subghz_bruteforcer/scenes/subbrute_scene_save_name.c

@@ -0,0 +1,87 @@
+#include "../subbrute_i.h"
+#include "subbrute_scene.h"
+#include <toolbox/name_generator.h>
+
+#define TAG "SubBruteSceneSaveFile"
+
+void subbrute_scene_save_name_on_enter(void* context) {
+    SubBruteState* instance = (SubBruteState*)context;
+
+    // Setup view
+    TextInput* text_input = instance->text_input;
+    name_generator_make_auto(
+        instance->text_store,
+        sizeof(instance->text_store),
+        subbrute_protocol_file(instance->device->protocol_info->file));
+
+    text_input_set_header_text(text_input, "Name of file");
+    text_input_set_result_callback(
+        text_input,
+        subbrute_text_input_callback,
+        instance,
+        instance->text_store,
+        SUBBRUTE_MAX_LEN_NAME,
+        true);
+
+    furi_string_reset(instance->file_path);
+    furi_string_set_str(instance->file_path, SUBBRUTE_PATH);
+
+    ValidatorIsFile* validator_is_file = validator_is_file_alloc_init(
+        furi_string_get_cstr(instance->file_path), SUBBRUTE_FILE_EXT, "");
+    text_input_set_validator(text_input, validator_is_file_callback, validator_is_file);
+
+    view_dispatcher_switch_to_view(instance->view_dispatcher, SubBruteViewTextInput);
+}
+
+bool subbrute_scene_save_name_on_event(void* context, SceneManagerEvent event) {
+    SubBruteState* instance = (SubBruteState*)context;
+    bool consumed = false;
+
+    if(event.type == SceneManagerEventTypeBack) {
+        scene_manager_previous_scene(instance->scene_manager);
+        return true;
+    } else if(
+        event.type == SceneManagerEventTypeCustom &&
+        event.event == SubBruteCustomEventTypeTextEditDone) {
+#ifdef FURI_DEBUG
+        FURI_LOG_D(TAG, "Saving: %s", instance->text_store);
+#endif
+        bool success = false;
+        if(strcmp(instance->text_store, "") != 0) {
+            furi_string_reset(instance->file_path);
+            furi_string_cat_printf(
+                instance->file_path,
+                "%s/%s%s",
+                SUBBRUTE_PATH,
+                instance->text_store,
+                SUBBRUTE_FILE_EXT);
+
+            if(subbrute_device_save_file(
+                   instance->device, furi_string_get_cstr(instance->file_path))) {
+                scene_manager_next_scene(instance->scene_manager, SubBruteSceneSaveSuccess);
+                success = true;
+                consumed = true;
+            }
+        }
+
+        if(!success) {
+            dialog_message_show_storage_error(instance->dialogs, "Error during saving!");
+            consumed = scene_manager_search_and_switch_to_previous_scene(
+                instance->scene_manager, SubBruteSceneSetupAttack);
+        }
+    }
+    return consumed;
+}
+
+void subbrute_scene_save_name_on_exit(void* context) {
+    SubBruteState* instance = (SubBruteState*)context;
+
+    // Clear view
+    void* validator_context = text_input_get_validator_callback_context(instance->text_input);
+    text_input_set_validator(instance->text_input, NULL, NULL);
+    validator_is_file_free(validator_context);
+
+    text_input_reset(instance->text_input);
+
+    furi_string_reset(instance->file_path);
+}

+ 51 - 0
subghz_bruteforcer/scenes/subbrute_scene_save_success.c

@@ -0,0 +1,51 @@
+#include "../subbrute_i.h"
+#include "subbrute_scene.h"
+
+void subbrute_scene_save_success_on_enter(void* context) {
+    furi_assert(context);
+    SubBruteState* instance = context;
+
+    // Setup view
+    Popup* popup = instance->popup;
+    popup_set_icon(popup, 32, 5, &I_DolphinNice_96x59);
+    popup_set_header(popup, "Saved!", 13, 22, AlignLeft, AlignBottom);
+    popup_set_timeout(popup, 1500);
+    popup_set_context(popup, instance);
+    popup_set_callback(popup, subbrute_popup_closed_callback);
+    popup_enable_timeout(popup);
+    view_dispatcher_switch_to_view(instance->view_dispatcher, SubBruteViewPopup);
+}
+
+bool subbrute_scene_save_success_on_event(void* context, SceneManagerEvent event) {
+    furi_assert(context);
+
+    SubBruteState* instance = (SubBruteState*)context;
+    //SubBruteMainView* view = instance->view_main;
+
+    if(event.type == SceneManagerEventTypeCustom) {
+        if(event.event == SubBruteCustomEventTypePopupClosed) {
+            if(!scene_manager_search_and_switch_to_previous_scene(
+                   instance->scene_manager, SubBruteSceneSetupAttack)) {
+                scene_manager_next_scene(instance->scene_manager, SubBruteSceneStart);
+            }
+            return true;
+        }
+    }
+    return false;
+}
+
+void subbrute_scene_save_success_on_exit(void* context) {
+    furi_assert(context);
+
+    SubBruteState* instance = (SubBruteState*)context;
+
+    // Clear view
+    Popup* popup = instance->popup;
+    popup_set_header(popup, NULL, 0, 0, AlignCenter, AlignBottom);
+    popup_set_text(popup, NULL, 0, 0, AlignCenter, AlignTop);
+    popup_set_icon(popup, 0, 0, NULL);
+    popup_set_callback(popup, NULL);
+    popup_set_context(popup, NULL);
+    popup_set_timeout(popup, 0);
+    popup_disable_timeout(popup);
+}

+ 140 - 0
subghz_bruteforcer/scenes/subbrute_scene_setup_attack.c

@@ -0,0 +1,140 @@
+#include "../subbrute_i.h"
+#include "subbrute_scene.h"
+
+#define TAG "SubBruteSceneSetupAttack"
+
+static void subbrute_scene_setup_attack_callback(SubBruteCustomEvent event, void* context) {
+    furi_assert(context);
+
+    SubBruteState* instance = (SubBruteState*)context;
+    view_dispatcher_send_custom_event(instance->view_dispatcher, event);
+}
+
+static void
+    subbrute_scene_setup_attack_device_state_changed(void* context, SubBruteWorkerState state) {
+    furi_assert(context);
+
+    SubBruteState* instance = (SubBruteState*)context;
+
+    if(state == SubBruteWorkerStateIDLE) {
+        // Can't be IDLE on this step!
+        view_dispatcher_send_custom_event(instance->view_dispatcher, SubBruteCustomEventTypeError);
+    }
+}
+
+void subbrute_scene_setup_attack_on_enter(void* context) {
+    furi_assert(context);
+    SubBruteState* instance = (SubBruteState*)context;
+    SubBruteAttackView* view = instance->view_attack;
+
+    notification_message(instance->notifications, &sequence_reset_vibro);
+
+#ifdef FURI_DEBUG
+    FURI_LOG_D(TAG, "Enter Attack: %s", subbrute_protocol_name(instance->device->attack));
+#endif
+
+    subbrute_worker_set_callback(
+        instance->worker, subbrute_scene_setup_attack_device_state_changed, context);
+    if(subbrute_worker_is_running(instance->worker)) {
+        subbrute_worker_stop(instance->worker);
+        instance->device->current_step = subbrute_worker_get_step(instance->worker);
+    }
+
+    subbrute_attack_view_init_values(
+        view,
+        instance->device->attack,
+        instance->device->max_value,
+        instance->device->current_step,
+        false,
+        subbrute_worker_get_repeats(instance->worker));
+
+    instance->current_view = SubBruteViewAttack;
+    subbrute_attack_view_set_callback(view, subbrute_scene_setup_attack_callback, instance);
+    view_dispatcher_switch_to_view(instance->view_dispatcher, instance->current_view);
+}
+
+void subbrute_scene_setup_attack_on_exit(void* context) {
+    furi_assert(context);
+#ifdef FURI_DEBUG
+    FURI_LOG_D(TAG, "subbrute_scene_setup_attack_on_exit");
+#endif
+    SubBruteState* instance = (SubBruteState*)context;
+    subbrute_worker_stop(instance->worker);
+    notification_message(instance->notifications, &sequence_blink_stop);
+    notification_message(instance->notifications, &sequence_reset_vibro);
+}
+
+bool subbrute_scene_setup_attack_on_event(void* context, SceneManagerEvent event) {
+    SubBruteState* instance = (SubBruteState*)context;
+    SubBruteAttackView* view = instance->view_attack;
+    bool consumed = false;
+
+    if(event.type == SceneManagerEventTypeCustom) {
+        if(event.event == SubBruteCustomEventTypeTransmitStarted) {
+            scene_manager_next_scene(instance->scene_manager, SubBruteSceneRunAttack);
+        } else if(event.event == SubBruteCustomEventTypeSaveFile) {
+            subbrute_attack_view_init_values(
+                view,
+                instance->device->attack,
+                instance->device->max_value,
+                instance->device->current_step,
+                false,
+                instance->device->extra_repeats);
+            scene_manager_next_scene(instance->scene_manager, SubBruteSceneSaveName);
+        } else if(event.event == SubBruteCustomEventTypeExtraSettings) {
+            scene_manager_next_scene(instance->scene_manager, SubBruteSceneSetupExtra);
+        } else if(event.event == SubBruteCustomEventTypeBackPressed) {
+            subbrute_attack_view_init_values(
+                view,
+                instance->device->attack,
+                instance->device->max_value,
+                instance->device->current_step,
+                false,
+                instance->device->extra_repeats);
+            scene_manager_next_scene(instance->scene_manager, SubBruteSceneStart);
+        } else if(event.event == SubBruteCustomEventTypeError) {
+            notification_message(instance->notifications, &sequence_error);
+        } else if(event.event == SubBruteCustomEventTypeTransmitCustom) {
+            // We can transmit only in not working states
+            if(subbrute_worker_can_manual_transmit(instance->worker)) {
+                // MANUAL Transmit!
+                // Blink
+                notification_message(instance->notifications, &sequence_blink_green_100);
+                subbrute_worker_transmit_current_key(
+                    instance->worker, instance->device->current_step);
+                // Stop
+                notification_message(instance->notifications, &sequence_blink_stop);
+            }
+        } else if(event.event == SubBruteCustomEventTypeChangeStepUp) {
+            // +1
+            uint64_t step = subbrute_device_add_step(instance->device, 1);
+            subbrute_worker_set_step(instance->worker, step);
+            subbrute_attack_view_set_current_step(view, step);
+        } else if(event.event == SubBruteCustomEventTypeChangeStepUpMore) {
+            // +50
+            uint64_t step = subbrute_device_add_step(instance->device, 50);
+            subbrute_worker_set_step(instance->worker, step);
+            subbrute_attack_view_set_current_step(view, step);
+        } else if(event.event == SubBruteCustomEventTypeChangeStepDown) {
+            // -1
+            uint64_t step = subbrute_device_add_step(instance->device, -1);
+            subbrute_worker_set_step(instance->worker, step);
+            subbrute_attack_view_set_current_step(view, step);
+        } else if(event.event == SubBruteCustomEventTypeChangeStepDownMore) {
+            // -50
+            uint64_t step = subbrute_device_add_step(instance->device, -50);
+            subbrute_worker_set_step(instance->worker, step);
+            subbrute_attack_view_set_current_step(view, step);
+        }
+
+        consumed = true;
+    } else if(event.type == SceneManagerEventTypeTick) {
+        if(subbrute_worker_is_running(instance->worker)) {
+            instance->device->current_step = subbrute_worker_get_step(instance->worker);
+        }
+        subbrute_attack_view_set_current_step(view, instance->device->current_step);
+        consumed = true;
+    }
+
+    return consumed;
+}

+ 282 - 0
subghz_bruteforcer/scenes/subbrute_scene_setup_extra.c

@@ -0,0 +1,282 @@
+#include "../subbrute_i.h"
+#include "subbrute_scene.h"
+
+#define TAG "SubBruteSceneLoadFile"
+
+#define MIN_TD 0
+#define MAX_TD 255
+#define MIN_REP 1
+#define MAX_REP 100
+#define MIN_TE 100
+#define MAX_TE 600
+
+enum SubBruteVarListIndex {
+    SubBruteVarListIndexTimeDelay,
+    SubBruteVarListIndexRepeatOrOnExtra,
+    SubBruteVarListIndexTe,
+};
+
+static void setup_extra_enter_callback(void* context, uint32_t index);
+
+static void setup_extra_td_callback(VariableItem* item) {
+    furi_assert(item);
+    SubBruteState* instance = variable_item_get_context(item);
+    furi_assert(instance);
+    char buf[6];
+
+    const uint8_t index = variable_item_get_current_value_index(item);
+    uint8_t val = subbrute_worker_get_timeout(instance->worker);
+
+    if(index == 0) {
+        if(val > MIN_TD) {
+            val--;
+            subbrute_worker_set_timeout(instance->worker, val);
+            snprintf(&buf[0], 5, "%d", val);
+            variable_item_set_current_value_text(item, &buf[0]);
+            variable_item_set_current_value_index(item, 1);
+            if(val == MIN_TD) {
+                variable_item_set_current_value_index(item, 0);
+            }
+        }
+    } else if(index == 2) {
+        if(val < MAX_TD) {
+            val++;
+            subbrute_worker_set_timeout(instance->worker, val);
+            snprintf(&buf[0], 5, "%d", val);
+            variable_item_set_current_value_text(item, &buf[0]);
+            variable_item_set_current_value_index(item, 1);
+            if(val == MAX_TD) {
+                variable_item_set_current_value_index(item, 2);
+            }
+        }
+    } else if(index == 1) {
+        if(val == MIN_TD) {
+            val++;
+            subbrute_worker_set_timeout(instance->worker, val);
+            snprintf(&buf[0], 5, "%d", val);
+            variable_item_set_current_value_text(item, &buf[0]);
+            variable_item_set_current_value_index(item, 1);
+            if(val == MAX_TD) {
+                variable_item_set_current_value_index(item, 2);
+            }
+        } else if(val == MAX_TD) {
+            val--;
+            subbrute_worker_set_timeout(instance->worker, val);
+            snprintf(&buf[0], 5, "%d", val);
+            variable_item_set_current_value_text(item, &buf[0]);
+            variable_item_set_current_value_index(item, 1);
+            if(val == MIN_TD) {
+                variable_item_set_current_value_index(item, 0);
+            }
+        }
+    }
+}
+
+static void setup_extra_rep_callback(VariableItem* item) {
+    furi_assert(item);
+    SubBruteState* instance = variable_item_get_context(item);
+    furi_assert(instance);
+    char buf[6];
+
+    const uint8_t index = variable_item_get_current_value_index(item);
+    uint8_t val = subbrute_worker_get_repeats(instance->worker);
+
+    if(index == 0) {
+        if(val > MIN_REP) {
+            val--;
+            subbrute_worker_set_repeats(instance->worker, val);
+            snprintf(&buf[0], 5, "%d", val);
+            variable_item_set_current_value_text(item, &buf[0]);
+            variable_item_set_current_value_index(item, 1);
+            if(val == MIN_REP) {
+                variable_item_set_current_value_index(item, 0);
+            }
+        }
+    } else if(index == 2) {
+        if(val < MAX_REP) {
+            val++;
+            subbrute_worker_set_repeats(instance->worker, val);
+            snprintf(&buf[0], 5, "%d", val);
+            variable_item_set_current_value_text(item, &buf[0]);
+            variable_item_set_current_value_index(item, 1);
+            if(val == MAX_REP) {
+                variable_item_set_current_value_index(item, 2);
+            }
+        }
+    } else if(index == 1) {
+        if(val == MIN_REP) {
+            val++;
+            subbrute_worker_set_repeats(instance->worker, val);
+            snprintf(&buf[0], 5, "%d", val);
+            variable_item_set_current_value_text(item, &buf[0]);
+            variable_item_set_current_value_index(item, 1);
+            if(val == MAX_REP) {
+                variable_item_set_current_value_index(item, 2);
+            }
+        } else if(val == MAX_REP) {
+            val--;
+            subbrute_worker_set_repeats(instance->worker, val);
+            snprintf(&buf[0], 5, "%d", val);
+            variable_item_set_current_value_text(item, &buf[0]);
+            variable_item_set_current_value_index(item, 1);
+            if(val == MIN_REP) {
+                variable_item_set_current_value_index(item, 0);
+            }
+        }
+    }
+}
+
+static void setup_extra_te_callback(VariableItem* item) {
+    furi_assert(item);
+    SubBruteState* instance = variable_item_get_context(item);
+    furi_assert(instance);
+    char buf[6];
+
+    const uint8_t index = variable_item_get_current_value_index(item);
+    uint32_t val = subbrute_worker_get_te(instance->worker);
+
+    if(index == 0) {
+        if(val > MIN_TE) {
+            val--;
+            subbrute_worker_set_te(instance->worker, val);
+            snprintf(&buf[0], 5, "%ld", val);
+            variable_item_set_current_value_text(item, &buf[0]);
+            variable_item_set_current_value_index(item, 1);
+            if(val == MIN_TE) {
+                variable_item_set_current_value_index(item, 0);
+            }
+        }
+    } else if(index == 2) {
+        if(val < MAX_TE) {
+            val++;
+            subbrute_worker_set_te(instance->worker, val);
+            snprintf(&buf[0], 5, "%ld", val);
+            variable_item_set_current_value_text(item, &buf[0]);
+            variable_item_set_current_value_index(item, 1);
+            if(val == MAX_TE) {
+                variable_item_set_current_value_index(item, 2);
+            }
+        }
+    } else if(index == 1) {
+        if(val == MIN_TE) {
+            val++;
+            subbrute_worker_set_te(instance->worker, val);
+            snprintf(&buf[0], 5, "%ld", val);
+            variable_item_set_current_value_text(item, &buf[0]);
+            variable_item_set_current_value_index(item, 1);
+            if(val == MAX_TE) {
+                variable_item_set_current_value_index(item, 2);
+            }
+        } else if(val == MAX_TE) {
+            val--;
+            subbrute_worker_set_te(instance->worker, val);
+            snprintf(&buf[0], 5, "%ld", val);
+            variable_item_set_current_value_text(item, &buf[0]);
+            variable_item_set_current_value_index(item, 1);
+            if(val == MIN_TE) {
+                variable_item_set_current_value_index(item, 0);
+            }
+        }
+    }
+}
+
+static void subbrute_scene_setup_extra_init_var_list(SubBruteState* instance, bool on_extra) {
+    furi_assert(instance);
+    char str[6];
+    VariableItem* item;
+    static bool extra = false;
+    if(on_extra) {
+        extra = true;
+    }
+
+    VariableItemList* var_list = instance->var_list;
+
+    variable_item_list_reset(var_list);
+
+    item = variable_item_list_add(var_list, "TimeDelay", 3, setup_extra_td_callback, instance);
+    snprintf(&str[0], 5, "%d", subbrute_worker_get_timeout(instance->worker));
+    variable_item_set_current_value_text(item, &str[0]);
+    switch(subbrute_worker_get_timeout(instance->worker)) {
+    case MIN_TD:
+        variable_item_set_current_value_index(item, 0);
+        break;
+    case MAX_TD:
+        variable_item_set_current_value_index(item, 2);
+        break;
+
+    default:
+        variable_item_set_current_value_index(item, 1);
+        break;
+    }
+
+    if(extra) {
+        item = variable_item_list_add(var_list, "Repeats", 3, setup_extra_rep_callback, instance);
+        snprintf(&str[0], 5, "%d", subbrute_worker_get_repeats(instance->worker));
+        variable_item_set_current_value_text(item, &str[0]);
+        switch(subbrute_worker_get_repeats(instance->worker)) {
+        case MIN_REP:
+            variable_item_set_current_value_index(item, 0);
+            break;
+        case MAX_REP:
+            variable_item_set_current_value_index(item, 2);
+            break;
+
+        default:
+            variable_item_set_current_value_index(item, 1);
+            break;
+        }
+        const uint32_t te = subbrute_worker_get_te(instance->worker);
+        if(te != 0) {
+            item = variable_item_list_add(var_list, "Te", 3, setup_extra_te_callback, instance);
+            snprintf(&str[0], 5, "%ld", te);
+            variable_item_set_current_value_text(item, &str[0]);
+            switch(te) {
+            case MIN_TE:
+                variable_item_set_current_value_index(item, 0);
+                break;
+            case MAX_TE:
+                variable_item_set_current_value_index(item, 2);
+                break;
+
+            default:
+                variable_item_set_current_value_index(item, 1);
+                break;
+            }
+        }
+    } else {
+        item = variable_item_list_add(var_list, "Show Extra", 0, NULL, NULL);
+        variable_item_set_current_value_index(item, 0);
+    }
+
+    variable_item_list_set_enter_callback(var_list, setup_extra_enter_callback, instance);
+    view_dispatcher_switch_to_view(instance->view_dispatcher, SubBruteViewVarList);
+}
+
+static void setup_extra_enter_callback(void* context, uint32_t index) {
+    furi_assert(context);
+    SubBruteState* instance = context;
+
+    if(index == SubBruteVarListIndexRepeatOrOnExtra) {
+        subbrute_scene_setup_extra_init_var_list(instance, true);
+    }
+}
+
+void subbrute_scene_setup_extra_on_enter(void* context) {
+    furi_assert(context);
+    SubBruteState* instance = context;
+
+    subbrute_scene_setup_extra_init_var_list(instance, false);
+}
+
+void subbrute_scene_setup_extra_on_exit(void* context) {
+    furi_assert(context);
+    SubBruteState* instance = context;
+
+    variable_item_list_reset(instance->var_list);
+}
+
+bool subbrute_scene_setup_extra_on_event(void* context, SceneManagerEvent event) {
+    UNUSED(context);
+    UNUSED(event);
+    return false;
+}

+ 95 - 0
subghz_bruteforcer/scenes/subbrute_scene_start.c

@@ -0,0 +1,95 @@
+#include "../subbrute_i.h"
+#include "subbrute_scene.h"
+
+#define TAG "SubBruteSceneStart"
+
+void subbrute_scene_start_callback(SubBruteCustomEvent event, void* context) {
+    furi_assert(context);
+
+    SubBruteState* instance = (SubBruteState*)context;
+    view_dispatcher_send_custom_event(instance->view_dispatcher, event);
+}
+
+void subbrute_scene_start_on_enter(void* context) {
+    furi_assert(context);
+#ifdef FURI_DEBUG
+    FURI_LOG_I(TAG, "subbrute_scene_start_on_enter");
+#endif
+    SubBruteState* instance = (SubBruteState*)context;
+    SubBruteMainView* view = instance->view_main;
+
+    instance->current_view = SubBruteViewMain;
+    subbrute_main_view_set_callback(view, subbrute_scene_start_callback, instance);
+
+    instance->device->attack = instance->settings->last_index;
+
+    subbrute_main_view_set_index(
+        view,
+        instance->settings->last_index,
+        instance->settings->repeat_values,
+        false,
+        instance->device->two_bytes,
+        0);
+
+    view_dispatcher_switch_to_view(instance->view_dispatcher, instance->current_view);
+}
+
+void subbrute_scene_start_on_exit(void* context) {
+    furi_assert(context);
+}
+
+bool subbrute_scene_start_on_event(void* context, SceneManagerEvent event) {
+    SubBruteState* instance = (SubBruteState*)context;
+    bool consumed = false;
+
+    if(event.type == SceneManagerEventTypeCustom) {
+#ifdef FURI_DEBUG
+        FURI_LOG_D(
+            TAG,
+            "Event: %ld, SubBruteCustomEventTypeMenuSelected: %s, SubBruteCustomEventTypeLoadFile: %s",
+            event.event,
+            event.event == SubBruteCustomEventTypeMenuSelected ? "true" : "false",
+            event.event == SubBruteCustomEventTypeLoadFile ? "true" : "false");
+#endif
+        if(event.event == SubBruteCustomEventTypeMenuSelected) {
+            instance->settings->last_index = subbrute_main_view_get_index(instance->view_main);
+            subbrute_settings_set_repeats(
+                instance->settings, subbrute_main_view_get_repeats(instance->view_main));
+            uint8_t total_repeats = subbrute_settings_get_current_repeats(instance->settings);
+
+            if((subbrute_device_attack_set(
+                    instance->device, instance->settings->last_index, total_repeats) !=
+                SubBruteFileResultOk) ||
+               (!subbrute_worker_init_default_attack(
+                   instance->worker,
+                   instance->settings->last_index,
+                   instance->device->current_step,
+                   instance->device->protocol_info,
+                   instance->device->extra_repeats))) {
+                furi_crash("Invalid attack set!");
+            }
+            subbrute_settings_save(instance->settings);
+            scene_manager_next_scene(instance->scene_manager, SubBruteSceneSetupAttack);
+
+            consumed = true;
+        } else if(event.event == SubBruteCustomEventTypeLoadFile) {
+            //uint8_t extra_repeats = subbrute_main_view_get_extra_repeats(instance->view_main);
+
+            //instance->device->extra_repeats = extra_repeats;
+            scene_manager_next_scene(instance->scene_manager, SubBruteSceneLoadFile);
+            consumed = true;
+        }
+    } else if(event.type == SceneManagerEventTypeBack) {
+        //exit app
+        instance->settings->last_index = subbrute_main_view_get_index(instance->view_main);
+        subbrute_settings_set_repeats(
+            instance->settings, subbrute_main_view_get_repeats(instance->view_main));
+        subbrute_settings_save(instance->settings);
+
+        scene_manager_stop(instance->scene_manager);
+        view_dispatcher_stop(instance->view_dispatcher);
+        consumed = true;
+    }
+
+    return consumed;
+}

+ 30 - 0
subghz_bruteforcer/scenes/subbute_scene.c

@@ -0,0 +1,30 @@
+#include "subbrute_scene.h"
+
+// Generate scene on_enter handlers array
+#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_enter,
+void (*const subbrute_on_enter_handlers[])(void*) = {
+#include "subbrute_scene_config.h"
+};
+#undef ADD_SCENE
+
+// Generate scene on_event handlers array
+#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_event,
+bool (*const subbrute_on_event_handlers[])(void* context, SceneManagerEvent event) = {
+#include "subbrute_scene_config.h"
+};
+#undef ADD_SCENE
+
+// Generate scene on_exit handlers array
+#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_exit,
+void (*const subbrute_on_exit_handlers[])(void* context) = {
+#include "subbrute_scene_config.h"
+};
+#undef ADD_SCENE
+
+// Initialize scene handlers configuration structure
+const SceneManagerHandlers subbrute_scene_handlers = {
+    .on_enter_handlers = subbrute_on_enter_handlers,
+    .on_event_handlers = subbrute_on_event_handlers,
+    .on_exit_handlers = subbrute_on_exit_handlers,
+    .scene_num = SubBruteSceneNum,
+};

BIN
subghz_bruteforcer/screenshots/screenshot_01.png


BIN
subghz_bruteforcer/screenshots/screenshot_02.png


BIN
subghz_bruteforcer/screenshots/screenshot_03.png


BIN
subghz_bruteforcer/screenshots/screenshot_04.png


BIN
subghz_bruteforcer/screenshots/screenshot_05.png


+ 220 - 0
subghz_bruteforcer/subbrute.c

@@ -0,0 +1,220 @@
+#include "subbrute_i.h"
+#include "scenes/subbrute_scene.h"
+
+#define TAG "SubBruteApp"
+
+static bool subbrute_custom_event_callback(void* context, uint32_t event) {
+    furi_assert(context);
+    SubBruteState* instance = context;
+    return scene_manager_handle_custom_event(instance->scene_manager, event);
+}
+
+static bool subbrute_back_event_callback(void* context) {
+    furi_assert(context);
+    SubBruteState* instance = context;
+    return scene_manager_handle_back_event(instance->scene_manager);
+}
+
+static void subbrute_tick_event_callback(void* context) {
+    furi_assert(context);
+    SubBruteState* instance = context;
+    scene_manager_handle_tick_event(instance->scene_manager);
+}
+
+SubBruteState* subbrute_alloc() {
+    SubBruteState* instance = malloc(sizeof(SubBruteState));
+
+    memset(instance->text_store, 0, sizeof(instance->text_store));
+    instance->file_path = furi_string_alloc();
+
+    instance->scene_manager = scene_manager_alloc(&subbrute_scene_handlers, instance);
+    instance->view_dispatcher = view_dispatcher_alloc();
+
+    instance->gui = furi_record_open(RECORD_GUI);
+
+    view_dispatcher_enable_queue(instance->view_dispatcher);
+    view_dispatcher_set_event_callback_context(instance->view_dispatcher, instance);
+    view_dispatcher_set_custom_event_callback(
+        instance->view_dispatcher, subbrute_custom_event_callback);
+    view_dispatcher_set_navigation_event_callback(
+        instance->view_dispatcher, subbrute_back_event_callback);
+    view_dispatcher_set_tick_event_callback(
+        instance->view_dispatcher, subbrute_tick_event_callback, 100);
+
+    //Dialog
+    instance->dialogs = furi_record_open(RECORD_DIALOGS);
+
+    // Notifications
+    instance->notifications = furi_record_open(RECORD_NOTIFICATION);
+
+    subghz_devices_init();
+
+    // init radio device
+    instance->radio_device = subbrute_radio_device_loader_set(
+        instance->radio_device, SubGhzRadioDeviceTypeExternalCC1101);
+
+    subghz_devices_reset(instance->radio_device);
+    subghz_devices_idle(instance->radio_device);
+
+    // Devices
+    instance->device = subbrute_device_alloc(instance->radio_device);
+
+    // SubBruteWorker
+    instance->worker = subbrute_worker_alloc(instance->radio_device);
+
+    // TextInput
+    instance->text_input = text_input_alloc();
+    view_dispatcher_add_view(
+        instance->view_dispatcher,
+        SubBruteViewTextInput,
+        text_input_get_view(instance->text_input));
+
+    // Custom Widget
+    instance->widget = widget_alloc();
+    view_dispatcher_add_view(
+        instance->view_dispatcher, SubBruteViewWidget, widget_get_view(instance->widget));
+
+    // VarList
+    instance->var_list = variable_item_list_alloc();
+    view_dispatcher_add_view(
+        instance->view_dispatcher,
+        SubBruteViewVarList,
+        variable_item_list_get_view(instance->var_list));
+
+    // Popup
+    instance->popup = popup_alloc();
+    view_dispatcher_add_view(
+        instance->view_dispatcher, SubBruteViewPopup, popup_get_view(instance->popup));
+
+    // ViewStack
+    instance->view_stack = view_stack_alloc();
+    view_dispatcher_add_view(
+        instance->view_dispatcher, SubBruteViewStack, view_stack_get_view(instance->view_stack));
+
+    // SubBruteMainView
+    instance->view_main = subbrute_main_view_alloc();
+    view_dispatcher_add_view(
+        instance->view_dispatcher,
+        SubBruteViewMain,
+        subbrute_main_view_get_view(instance->view_main));
+
+    // SubBruteAttackView
+    instance->view_attack = subbrute_attack_view_alloc();
+    view_dispatcher_add_view(
+        instance->view_dispatcher,
+        SubBruteViewAttack,
+        subbrute_attack_view_get_view(instance->view_attack));
+
+    instance->settings = subbrute_settings_alloc();
+    subbrute_settings_load(instance->settings);
+    //instance->flipper_format = flipper_format_string_alloc();
+    //instance->environment = subghz_environment_alloc();
+
+    // Uncomment to enable Debug pin output on PIN 17(1W)
+    // subghz_devices_set_async_mirror_pin(instance->radio_device, &gpio_ibutton);
+
+    return instance;
+}
+
+void subbrute_free(SubBruteState* instance) {
+    furi_assert(instance);
+
+    // Uncomment to enable Debug pin output on PIN 17(1W)
+    // subghz_devices_set_async_mirror_pin(instance->radio_device, NULL);
+
+    // SubBruteWorker
+    subbrute_worker_stop(instance->worker);
+    subbrute_worker_free(instance->worker);
+
+    // SubBruteDevice
+    subbrute_device_free(instance->device);
+    subghz_devices_deinit();
+
+    //subbrute_settings_save(instance->settings);
+    subbrute_settings_free(instance->settings);
+
+    // Notifications
+    notification_message(instance->notifications, &sequence_blink_stop);
+    furi_record_close(RECORD_NOTIFICATION);
+    instance->notifications = NULL;
+
+    // View Main
+    view_dispatcher_remove_view(instance->view_dispatcher, SubBruteViewMain);
+    subbrute_main_view_free(instance->view_main);
+
+    // View Attack
+    view_dispatcher_remove_view(instance->view_dispatcher, SubBruteViewAttack);
+    subbrute_attack_view_free(instance->view_attack);
+
+    // TextInput
+    view_dispatcher_remove_view(instance->view_dispatcher, SubBruteViewTextInput);
+    text_input_free(instance->text_input);
+
+    // Custom Widget
+    view_dispatcher_remove_view(instance->view_dispatcher, SubBruteViewWidget);
+    widget_free(instance->widget);
+
+    // VarList
+    view_dispatcher_remove_view(instance->view_dispatcher, SubBruteViewVarList);
+    variable_item_list_free(instance->var_list);
+
+    // Popup
+    view_dispatcher_remove_view(instance->view_dispatcher, SubBruteViewPopup);
+    popup_free(instance->popup);
+
+    // ViewStack
+    view_dispatcher_remove_view(instance->view_dispatcher, SubBruteViewStack);
+    view_stack_free(instance->view_stack);
+
+    //Dialog
+    furi_record_close(RECORD_DIALOGS);
+    instance->dialogs = NULL;
+
+    // Scene manager
+    scene_manager_free(instance->scene_manager);
+
+    // View Dispatcher
+    view_dispatcher_free(instance->view_dispatcher);
+
+    // GUI
+    furi_record_close(RECORD_GUI);
+    instance->gui = NULL;
+
+    furi_string_free(instance->file_path);
+
+    // The rest
+    free(instance);
+}
+
+void subbrute_text_input_callback(void* context) {
+    furi_assert(context);
+    SubBruteState* instance = context;
+    view_dispatcher_send_custom_event(
+        instance->view_dispatcher, SubBruteCustomEventTypeTextEditDone);
+}
+
+void subbrute_popup_closed_callback(void* context) {
+    furi_assert(context);
+    SubBruteState* instance = context;
+    view_dispatcher_send_custom_event(
+        instance->view_dispatcher, SubBruteCustomEventTypePopupClosed);
+}
+
+// ENTRYPOINT
+int32_t subbrute_app(void* p) {
+    UNUSED(p);
+    furi_hal_power_suppress_charge_enter();
+
+    SubBruteState* instance = subbrute_alloc();
+    view_dispatcher_attach_to_gui(
+        instance->view_dispatcher, instance->gui, ViewDispatcherTypeFullscreen);
+    scene_manager_next_scene(instance->scene_manager, SubBruteSceneStart);
+
+    notification_message(instance->notifications, &sequence_display_backlight_on);
+    view_dispatcher_run(instance->view_dispatcher);
+
+    subbrute_free(instance);
+
+    furi_hal_power_suppress_charge_exit();
+    return 0;
+}

+ 3 - 0
subghz_bruteforcer/subbrute.h

@@ -0,0 +1,3 @@
+#pragma once
+
+typedef struct SubBruteState SubBruteState;

BIN
subghz_bruteforcer/subbrute_10px.png


+ 27 - 0
subghz_bruteforcer/subbrute_custom_event.h

@@ -0,0 +1,27 @@
+#pragma once
+
+typedef enum {
+    // Reserve first 100 events for button types and indexes, starting from 0
+    SubBruteCustomEventTypeReserved = 100,
+
+    SubBruteCustomEventTypeBackPressed,
+    SubBruteCustomEventTypeIndexSelected,
+    SubBruteCustomEventTypeTransmitStarted,
+    SubBruteCustomEventTypeError,
+    SubBruteCustomEventTypeTransmitFinished,
+    SubBruteCustomEventTypeTransmitNotStarted,
+    SubBruteCustomEventTypeTransmitCustom,
+    SubBruteCustomEventTypeSaveFile,
+    SubBruteCustomEventTypeExtraSettings,
+    SubBruteCustomEventTypeUpdateView,
+    SubBruteCustomEventTypeChangeStepUp,
+    SubBruteCustomEventTypeChangeStepDown,
+    SubBruteCustomEventTypeChangeStepUpMore,
+    SubBruteCustomEventTypeChangeStepDownMore,
+
+    SubBruteCustomEventTypeMenuSelected,
+    SubBruteCustomEventTypeTextEditDone,
+    SubBruteCustomEventTypePopupClosed,
+
+    SubBruteCustomEventTypeLoadFile,
+} SubBruteCustomEvent;

+ 469 - 0
subghz_bruteforcer/subbrute_device.c

@@ -0,0 +1,469 @@
+#include "subbrute_device.h"
+
+#include <storage/storage.h>
+#include <lib/flipper_format/flipper_format_i.h>
+#include <lib/subghz/subghz_protocol_registry.h>
+
+#define TAG "SubBruteDevice"
+
+SubBruteDevice* subbrute_device_alloc(const SubGhzDevice* radio_device) {
+    SubBruteDevice* instance = malloc(sizeof(SubBruteDevice));
+
+    instance->current_step = 0;
+
+    instance->protocol_info = NULL;
+    instance->file_protocol_info = NULL;
+    instance->decoder_result = NULL;
+    instance->receiver = NULL;
+    instance->environment = subghz_environment_alloc();
+    subghz_environment_set_protocol_registry(
+        instance->environment, (void*)&subghz_protocol_registry);
+
+    instance->radio_device = radio_device;
+
+//#ifdef FURI_DEBUG
+//    subbrute_device_attack_set_default_values(instance, SubBruteAttackLoadFile);
+//#else
+    subbrute_device_attack_set_default_values(instance, SubBruteAttackCAME12bit433);
+//#endif
+    return instance;
+}
+
+void subbrute_device_free(SubBruteDevice* instance) {
+    furi_assert(instance);
+
+    // I don't know how to free this
+    instance->decoder_result = NULL;
+
+    if(instance->receiver != NULL) {
+        subghz_receiver_free(instance->receiver);
+        instance->receiver = NULL;
+    }
+
+    subghz_environment_free(instance->environment);
+    instance->environment = NULL;
+
+    subbrute_device_free_protocol_info(instance);
+
+    free(instance);
+}
+
+uint64_t subbrute_device_add_step(SubBruteDevice* instance, int8_t step) {
+    if(step > 0) {
+        if((instance->current_step + step) - instance->max_value == 1) {
+            instance->current_step = 0x00;
+        } else {
+            uint64_t value = instance->current_step + step;
+            if(value == instance->max_value) {
+                instance->current_step = value;
+            } else {
+                instance->current_step = value % instance->max_value;
+            }
+        }
+    } else {
+        if(instance->current_step + step == 0) {
+            instance->current_step = 0x00;
+        } else if(instance->current_step == 0) {
+            instance->current_step = instance->max_value;
+        } else {
+            uint64_t value = ((instance->current_step + step) + instance->max_value);
+            if(value == instance->max_value) {
+                instance->current_step = value;
+            } else {
+                instance->current_step = value % instance->max_value;
+            }
+        }
+    }
+
+    return instance->current_step;
+}
+
+bool subbrute_device_save_file(SubBruteDevice* instance, const char* dev_file_name) {
+    furi_assert(instance);
+
+#ifdef FURI_DEBUG
+    FURI_LOG_D(TAG, "subbrute_device_save_file: %s", dev_file_name);
+#endif
+
+    Storage* storage = furi_record_open(RECORD_STORAGE);
+    FlipperFormat* file = flipper_format_file_alloc(storage);
+    bool result = false;
+    do {
+        if(!flipper_format_file_open_always(file, dev_file_name)) {
+            FURI_LOG_E(TAG, "Failed to open file: %s", dev_file_name);
+            break;
+        }
+        Stream* stream = flipper_format_get_raw_stream(file);
+        if(instance->attack == SubBruteAttackLoadFile) {
+            subbrute_protocol_file_generate_file(
+                stream,
+                instance->file_protocol_info->frequency,
+                instance->file_protocol_info->preset,
+                instance->file_protocol_info->file,
+                instance->current_step,
+                instance->file_protocol_info->bits,
+                instance->file_protocol_info->te,
+                instance->bit_index,
+                instance->key_from_file,
+                instance->two_bytes);
+        } else {
+            subbrute_protocol_default_generate_file(
+                stream,
+                instance->protocol_info->frequency,
+                instance->protocol_info->preset,
+                instance->protocol_info->file,
+                instance->current_step,
+                instance->protocol_info->bits,
+                instance->protocol_info->te);
+        }
+
+        result = true;
+    } while(false);
+
+    if(!result) {
+        FURI_LOG_E(TAG, "subbrute_device_save_file failed!");
+    }
+
+    flipper_format_file_close(file);
+    flipper_format_free(file);
+    furi_record_close(RECORD_STORAGE);
+
+    return result;
+}
+
+SubBruteFileResult subbrute_device_attack_set(
+    SubBruteDevice* instance,
+    SubBruteAttacks type,
+    uint8_t extra_repeats) {
+    furi_assert(instance);
+#ifdef FURI_DEBUG
+    FURI_LOG_D(TAG, "subbrute_device_attack_set: %d, extra_repeats: %d", type, extra_repeats);
+#endif
+    subbrute_device_attack_set_default_values(instance, type);
+
+    if(type != SubBruteAttackLoadFile) {
+        subbrute_device_free_protocol_info(instance);
+        instance->protocol_info = subbrute_protocol(type);
+    }
+
+    instance->extra_repeats = extra_repeats;
+
+    // For non-file types we didn't set SubGhzProtocolDecoderBase
+    instance->receiver = subghz_receiver_alloc_init(instance->environment);
+    subghz_receiver_set_filter(instance->receiver, SubGhzProtocolFlag_Decodable);
+    // furi_hal_subghz_reset(); // TODO Is this necessary?
+
+    uint8_t protocol_check_result = SubBruteFileResultProtocolNotFound;
+#ifdef FURI_DEBUG
+    uint8_t bits;
+    uint32_t te;
+    uint8_t repeat;
+    FuriHalSubGhzPreset preset;
+    SubBruteFileProtocol file;
+#endif
+    if(type != SubBruteAttackLoadFile) {
+        instance->decoder_result = subghz_receiver_search_decoder_base_by_name(
+            instance->receiver, subbrute_protocol_file(instance->protocol_info->file));
+
+        if(!instance->decoder_result ||
+           instance->decoder_result->protocol->type == SubGhzProtocolTypeDynamic) {
+            FURI_LOG_E(TAG, "Can't load SubGhzProtocolDecoderBase in phase non-file decoder set");
+        } else {
+            protocol_check_result = SubBruteFileResultOk;
+
+            // Calc max value
+            instance->max_value = subbrute_protocol_calc_max_value(
+                instance->attack, instance->protocol_info->bits, instance->two_bytes);
+        }
+#ifdef FURI_DEBUG
+        bits = instance->protocol_info->bits;
+        te = instance->protocol_info->te;
+        repeat = instance->protocol_info->repeat + instance->extra_repeats;
+        preset = instance->protocol_info->preset;
+        file = instance->protocol_info->file;
+#endif
+    } else {
+        // And here we need to set preset enum
+        protocol_check_result = SubBruteFileResultOk;
+
+        // Calc max value
+        instance->max_value = subbrute_protocol_calc_max_value(
+            instance->attack, instance->file_protocol_info->bits, instance->two_bytes);
+#ifdef FURI_DEBUG
+        bits = instance->file_protocol_info->bits;
+        te = instance->file_protocol_info->te;
+        repeat = instance->file_protocol_info->repeat + instance->extra_repeats;
+        preset = instance->file_protocol_info->preset;
+        file = instance->file_protocol_info->file;
+#endif
+    }
+
+    subghz_receiver_free(instance->receiver);
+    instance->receiver = NULL;
+
+    if(protocol_check_result != SubBruteFileResultOk) {
+        return SubBruteFileResultProtocolNotFound;
+    }
+
+#ifdef FURI_DEBUG
+    FURI_LOG_I(
+        TAG,
+        "subbrute_device_attack_set: %s, bits: %d, preset: %s, file: %s, te: %ld, repeat: %d, max_value: %lld",
+        subbrute_protocol_name(instance->attack),
+        bits,
+        subbrute_protocol_preset(preset),
+        subbrute_protocol_file(file),
+        te,
+        repeat,
+        instance->max_value);
+#endif
+
+    return SubBruteFileResultOk;
+}
+
+uint8_t subbrute_device_load_from_file(SubBruteDevice* instance, const char* file_path) {
+    furi_assert(instance);
+#ifdef FURI_DEBUG
+    FURI_LOG_D(TAG, "subbrute_device_load_from_file: %s", file_path);
+#endif
+    SubBruteFileResult result;
+
+    Storage* storage = furi_record_open(RECORD_STORAGE);
+    FlipperFormat* fff_data_file = flipper_format_file_alloc(storage);
+
+    subbrute_device_free_protocol_info(instance);
+    instance->file_protocol_info = malloc(sizeof(SubBruteProtocol));
+
+    FuriString* temp_str;
+    temp_str = furi_string_alloc();
+    uint32_t temp_data32;
+
+    instance->receiver = subghz_receiver_alloc_init(instance->environment);
+    subghz_receiver_set_filter(instance->receiver, SubGhzProtocolFlag_Decodable);
+    // furi_hal_subghz_reset(); // TODO Is this necessary?
+
+    do {
+        if(!flipper_format_file_open_existing(fff_data_file, file_path)) {
+            FURI_LOG_E(TAG, "Error open file %s", file_path);
+            result = SubBruteFileResultErrorOpenFile;
+            break;
+        }
+        if(!flipper_format_read_header(fff_data_file, temp_str, &temp_data32)) {
+            FURI_LOG_E(TAG, "Missing or incorrect header");
+            result = SubBruteFileResultMissingOrIncorrectHeader;
+            break;
+        }
+
+        // Frequency
+        if(!flipper_format_read_uint32(fff_data_file, "Frequency", &temp_data32, 1)) {
+            FURI_LOG_E(TAG, "Missing or incorrect Frequency");
+            result = SubBruteFileResultMissingOrIncorrectFrequency;
+            break;
+        }
+
+        if(!subghz_devices_is_frequency_valid(instance->radio_device, temp_data32)) {
+            FURI_LOG_E(TAG, "Unsupported radio device frequency");
+            result = SubBruteFileResultMissingOrIncorrectFrequency;
+            break;
+        }
+
+        instance->file_protocol_info->frequency =
+            subghz_devices_set_frequency(instance->radio_device, temp_data32);
+
+        if(!subghz_devices_set_tx(instance->radio_device)) {
+            subghz_devices_idle(instance->radio_device);
+            result = SubBruteFileResultFrequencyNotAllowed;
+            break;
+        }
+        subghz_devices_idle(instance->radio_device);
+
+        // Preset
+        if(!flipper_format_read_string(fff_data_file, "Preset", temp_str)) {
+            FURI_LOG_E(TAG, "Preset FAIL");
+            result = SubBruteFileResultPresetInvalid;
+            break;
+        }
+        instance->file_protocol_info->preset = subbrute_protocol_convert_preset(temp_str);
+
+        const char* protocol_file = NULL;
+        // Protocol
+        if(!flipper_format_read_string(fff_data_file, "Protocol", temp_str)) {
+            FURI_LOG_E(TAG, "Missing Protocol");
+            result = SubBruteFileResultMissingProtocol;
+            break;
+        }
+        instance->file_protocol_info->file = subbrute_protocol_file_protocol_name(temp_str);
+        protocol_file = subbrute_protocol_file(instance->file_protocol_info->file);
+#ifdef FURI_DEBUG
+        FURI_LOG_D(TAG, "Protocol: %s", protocol_file);
+#endif
+
+        instance->decoder_result = subghz_receiver_search_decoder_base_by_name(
+            instance->receiver, furi_string_get_cstr(temp_str));
+
+        if((!instance->decoder_result) || (strcmp(protocol_file, "RAW") == 0) ||
+           (strcmp(protocol_file, "Unknown") == 0)) {
+            FURI_LOG_E(TAG, "Protocol unsupported");
+            result = SubBruteFileResultProtocolNotSupported;
+            break;
+        }
+
+        if(instance->decoder_result->protocol->type == SubGhzProtocolTypeDynamic) {
+            FURI_LOG_E(TAG, "Protocol is dynamic - not supported");
+            result = SubBruteFileResultDynamicProtocolNotValid;
+            break;
+        }
+#ifdef FURI_DEBUG
+        FURI_LOG_D(TAG, "Decoder: %s", instance->decoder_result->protocol->name);
+#endif
+
+        // Bit
+        if(!flipper_format_read_uint32(fff_data_file, "Bit", &temp_data32, 1)) {
+            FURI_LOG_E(TAG, "Missing or incorrect Bit");
+            result = SubBruteFileResultMissingOrIncorrectBit;
+            break;
+        }
+        instance->file_protocol_info->bits = temp_data32;
+#ifdef FURI_DEBUG
+        FURI_LOG_D(TAG, "Bit: %d", instance->file_protocol_info->bits);
+#endif
+
+        uint8_t key_data[sizeof(uint64_t)] = {0};
+        if(!flipper_format_read_hex(fff_data_file, "Key", key_data, sizeof(uint64_t))) {
+            FURI_LOG_E(TAG, "Missing Key");
+            result = SubBruteFileResultMissingOrIncorrectKey;
+            break;
+        }
+        uint64_t data = 0;
+        for(size_t i = 0; i < sizeof(uint64_t); i++) {
+            data = (data << 8) | key_data[i];
+        }
+#if FURI_DEBUG
+        FURI_LOG_D(TAG, "Key: %.16llX", data);
+#endif
+        instance->key_from_file = data;
+
+        // TE
+        if(!flipper_format_read_uint32(fff_data_file, "TE", &temp_data32, 1)) {
+            FURI_LOG_E(TAG, "Missing or incorrect TE");
+            //result = SubBruteFileResultMissingOrIncorrectTe;
+            //break;
+        } else {
+            instance->file_protocol_info->te = temp_data32 != 0 ? temp_data32 : 0;
+        }
+
+        // Repeat
+        if(flipper_format_read_uint32(fff_data_file, "Repeat", &temp_data32, 1)) {
+#ifdef FURI_DEBUG
+            FURI_LOG_D(TAG, "Repeat: %ld", temp_data32);
+#endif
+            instance->file_protocol_info->repeat = (uint8_t)temp_data32;
+        } else {
+#ifdef FURI_DEBUG
+            FURI_LOG_D(TAG, "Repeat: 3 (default)");
+#endif
+            instance->file_protocol_info->repeat = 3;
+        }
+
+        result = SubBruteFileResultOk;
+    } while(0);
+
+    furi_string_free(temp_str);
+    flipper_format_file_close(fff_data_file);
+    flipper_format_free(fff_data_file);
+    furi_record_close(RECORD_STORAGE);
+
+    subghz_receiver_free(instance->receiver);
+
+    instance->decoder_result = NULL;
+    instance->receiver = NULL;
+
+    if(result == SubBruteFileResultOk) {
+#ifdef FURI_DEBUG
+        FURI_LOG_D(TAG, "Loaded successfully");
+#endif
+    } else {
+        FURI_LOG_E(TAG, "Load failed!");
+        subbrute_device_free_protocol_info(instance);
+    }
+
+    return result;
+}
+
+void subbrute_device_attack_set_default_values(
+    SubBruteDevice* instance,
+    SubBruteAttacks default_attack) {
+    furi_assert(instance);
+#ifdef FURI_DEBUG
+    FURI_LOG_D(TAG, "subbrute_device_attack_set_default_values");
+#endif
+    instance->attack = default_attack;
+    instance->current_step = 0x00;
+    instance->bit_index = 0x00;
+    instance->extra_repeats = 0;
+    instance->two_bytes = false;
+
+    if(default_attack != SubBruteAttackLoadFile) {
+        instance->max_value = subbrute_protocol_calc_max_value(
+            instance->attack, instance->bit_index, instance->two_bytes);
+    }
+}
+
+const char* subbrute_device_error_get_desc(SubBruteFileResult error_id) {
+    const char* result;
+    switch(error_id) {
+    case(SubBruteFileResultOk):
+        result = "OK";
+        break;
+    case(SubBruteFileResultErrorOpenFile):
+        result = "invalid name/path";
+        break;
+    case(SubBruteFileResultMissingOrIncorrectHeader):
+        result = "Missing or incorrect header";
+        break;
+    case(SubBruteFileResultFrequencyNotAllowed):
+        result = "Invalid frequency!";
+        break;
+    case(SubBruteFileResultMissingOrIncorrectFrequency):
+        result = "Missing or incorrect Frequency";
+        break;
+    case(SubBruteFileResultPresetInvalid):
+        result = "Preset FAIL";
+        break;
+    case(SubBruteFileResultMissingProtocol):
+        result = "Missing Protocol";
+        break;
+    case(SubBruteFileResultProtocolNotSupported):
+        result = "Protocol unsupported";
+        break;
+    case(SubBruteFileResultDynamicProtocolNotValid):
+        result = "Dynamic protocol unsupported";
+        break;
+    case(SubBruteFileResultProtocolNotFound):
+        result = "Protocol not found";
+        break;
+    case(SubBruteFileResultMissingOrIncorrectBit):
+        result = "Missing or incorrect Bit";
+        break;
+    case(SubBruteFileResultMissingOrIncorrectKey):
+        result = "Missing or incorrect Key";
+        break;
+    case(SubBruteFileResultMissingOrIncorrectTe):
+        result = "Missing or incorrect TE";
+        break;
+    case SubBruteFileResultUnknown:
+    default:
+        result = "Unknown error";
+        break;
+    }
+    return result;
+}
+
+void subbrute_device_free_protocol_info(SubBruteDevice* instance) {
+    furi_assert(instance);
+    instance->protocol_info = NULL;
+    if(instance->file_protocol_info) {
+        free(instance->file_protocol_info);
+    }
+    instance->file_protocol_info = NULL;
+}

+ 74 - 0
subghz_bruteforcer/subbrute_device.h

@@ -0,0 +1,74 @@
+#pragma once
+
+#include "subbrute_protocols.h"
+#include <lib/subghz/protocols/base.h>
+#include <lib/subghz/transmitter.h>
+#include <lib/subghz/receiver.h>
+#include <lib/subghz/environment.h>
+#include "helpers/subbrute_radio_device_loader.h"
+
+#define SUBBRUTE_MAX_LEN_NAME 64
+#define SUBBRUTE_PATH EXT_PATH("subghz")
+#define SUBBRUTE_FILE_EXT ".sub"
+
+typedef enum {
+    SubBruteFileResultUnknown,
+    SubBruteFileResultOk,
+    SubBruteFileResultErrorOpenFile,
+    SubBruteFileResultMissingOrIncorrectHeader,
+    SubBruteFileResultFrequencyNotAllowed,
+    SubBruteFileResultMissingOrIncorrectFrequency,
+    SubBruteFileResultPresetInvalid,
+    SubBruteFileResultMissingProtocol,
+    SubBruteFileResultProtocolNotSupported,
+    SubBruteFileResultDynamicProtocolNotValid,
+    SubBruteFileResultProtocolNotFound,
+    SubBruteFileResultMissingOrIncorrectBit,
+    SubBruteFileResultMissingOrIncorrectKey,
+    SubBruteFileResultMissingOrIncorrectTe,
+} SubBruteFileResult;
+
+typedef struct {
+    const SubBruteProtocol* protocol_info;
+    SubBruteProtocol* file_protocol_info;
+
+    // Current step
+    uint64_t current_step;
+
+    // SubGhz
+    SubGhzReceiver* receiver;
+    SubGhzProtocolDecoderBase* decoder_result;
+    SubGhzEnvironment* environment;
+    const SubGhzDevice* radio_device;
+
+    // Attack state
+    SubBruteAttacks attack;
+    uint64_t max_value;
+    uint8_t extra_repeats;
+
+    // Loaded info for attack type
+    uint64_t key_from_file;
+    uint64_t current_key_from_file;
+    bool two_bytes;
+
+    // Index of group to bruteforce in loaded file
+    uint8_t bit_index;
+} SubBruteDevice;
+
+SubBruteDevice* subbrute_device_alloc(const SubGhzDevice* radio_device);
+void subbrute_device_free(SubBruteDevice* instance);
+
+bool subbrute_device_save_file(SubBruteDevice* instance, const char* key_name);
+const char* subbrute_device_error_get_desc(SubBruteFileResult error_id);
+SubBruteFileResult subbrute_device_attack_set(
+    SubBruteDevice* context,
+    SubBruteAttacks type,
+    uint8_t extra_repeats);
+uint8_t subbrute_device_load_from_file(SubBruteDevice* context, const char* file_path);
+
+uint64_t subbrute_device_add_step(SubBruteDevice* instance, int8_t step);
+
+void subbrute_device_free_protocol_info(SubBruteDevice* instance);
+void subbrute_device_attack_set_default_values(
+    SubBruteDevice* context,
+    SubBruteAttacks default_attack);

+ 89 - 0
subghz_bruteforcer/subbrute_i.h

@@ -0,0 +1,89 @@
+#pragma once
+
+#include <furi.h>
+#include <furi_hal.h>
+#include <input/input.h>
+
+#include <notification/notification.h>
+#include <notification/notification_messages.h>
+
+#include <gui/gui.h>
+#include <gui/view_dispatcher.h>
+#include <gui/view_stack.h>
+#include <gui/scene_manager.h>
+#include <gui/modules/text_input.h>
+#include <gui/modules/popup.h>
+#include <gui/modules/widget.h>
+#include <gui/modules/loading.h>
+#include <gui/modules/variable_item_list.h>
+
+#include "subghz_bruteforcer_icons.h"
+
+#include <assets_icons.h>
+
+#include <dialogs/dialogs.h>
+
+#include <notification/notification.h>
+#include <notification/notification_messages.h>
+
+#include "subbrute.h"
+#include "subbrute_device.h"
+#include "subbrute_settings.h"
+#include "helpers/subbrute_worker.h"
+#include "views/subbrute_attack_view.h"
+#include "views/subbrute_main_view.h"
+
+#define SUBBRUTEFORCER_VER "Sub-GHz BruteForcer 3.9"
+
+#ifdef FURI_DEBUG
+//#define SUBBRUTE_FAST_TRACK false
+#endif
+
+typedef enum {
+    SubBruteViewNone,
+    SubBruteViewMain,
+    SubBruteViewAttack,
+    SubBruteViewTextInput,
+    SubBruteViewDialogEx,
+    SubBruteViewPopup,
+    SubBruteViewWidget,
+    SubBruteViewStack,
+    SubBruteViewVarList,
+} SubBruteView;
+
+struct SubBruteState {
+    // GUI elements
+    NotificationApp* notifications;
+    Gui* gui;
+    ViewDispatcher* view_dispatcher;
+    ViewStack* view_stack;
+    TextInput* text_input;
+    Popup* popup;
+    Widget* widget;
+    VariableItemList* var_list;
+    DialogsApp* dialogs;
+    const SubGhzDevice* radio_device;
+
+    // Text store
+    char text_store[SUBBRUTE_MAX_LEN_NAME];
+    FuriString* file_path;
+
+    // Views
+    SubBruteMainView* view_main;
+    SubBruteAttackView* view_attack;
+    SubBruteView current_view;
+
+    // Scene
+    SceneManager* scene_manager;
+
+    // SubBruteDevice
+    SubBruteDevice* device;
+    // SubBruteWorker
+    SubBruteWorker* worker;
+    // Last used settings
+    SubBruteSettings* settings;
+};
+
+void subbrute_show_loading_popup(void* context, bool show);
+void subbrute_text_input_callback(void* context);
+void subbrute_popup_closed_callback(void* context);

+ 875 - 0
subghz_bruteforcer/subbrute_protocols.c

@@ -0,0 +1,875 @@
+#include "subbrute_protocols.h"
+#include "math.h"
+
+#define TAG "SubBruteProtocols"
+
+/**
+ * CAME 12bit 303MHz
+ */
+const SubBruteProtocol subbrute_protocol_came_12bit_303 = {
+    .frequency = 303875000,
+    .bits = 12,
+    .te = 0,
+    .repeat = 3,
+    .preset = FuriHalSubGhzPresetOok650Async,
+    .file = CAMEFileProtocol};
+
+/**
+ * CAME 12bit 307MHz
+ */
+const SubBruteProtocol subbrute_protocol_came_12bit_307 = {
+    .frequency = 307800000,
+    .bits = 12,
+    .te = 0,
+    .repeat = 3,
+    .preset = FuriHalSubGhzPresetOok650Async,
+    .file = CAMEFileProtocol};
+
+/**
+ * CAME 12bit 315MHz
+ */
+const SubBruteProtocol subbrute_protocol_came_12bit_315 = {
+    .frequency = 315000000,
+    .bits = 12,
+    .te = 0,
+    .repeat = 3,
+    .preset = FuriHalSubGhzPresetOok650Async,
+    .file = CAMEFileProtocol};
+
+/**
+ * CAME 12bit 433MHz
+ */
+const SubBruteProtocol subbrute_protocol_came_12bit_433 = {
+    .frequency = 433920000,
+    .bits = 12,
+    .te = 0,
+    .repeat = 3,
+    .preset = FuriHalSubGhzPresetOok650Async,
+    .file = CAMEFileProtocol};
+
+/**
+ * CAME 12bit 868MHz
+ */
+const SubBruteProtocol subbrute_protocol_came_12bit_868 = {
+    .frequency = 868350000,
+    .bits = 12,
+    .te = 0,
+    .repeat = 3,
+    .preset = FuriHalSubGhzPresetOok650Async,
+    .file = CAMEFileProtocol};
+
+/**
+ * NICE 12bit 433MHz
+ */
+const SubBruteProtocol subbrute_protocol_nice_12bit_433 = {
+    .frequency = 433920000,
+    .bits = 12,
+    .te = 0,
+    .repeat = 3,
+    .preset = FuriHalSubGhzPresetOok650Async,
+    .file = NICEFileProtocol};
+
+/**
+ * NICE 12bit 868MHz
+ */
+const SubBruteProtocol subbrute_protocol_nice_12bit_868 = {
+    .frequency = 868350000,
+    .bits = 12,
+    .te = 0,
+    .repeat = 3,
+    .preset = FuriHalSubGhzPresetOok650Async,
+    .file = NICEFileProtocol};
+
+/**
+ * Ansonic 12bit 433.075MHz
+ */
+const SubBruteProtocol subbrute_protocol_ansonic_12bit_433075 = {
+    .frequency = 433075000,
+    .bits = 12,
+    .te = 0,
+    .repeat = 3,
+    .preset = FuriHalSubGhzPreset2FSKDev238Async,
+    .file = AnsonicFileProtocol};
+
+/**
+ * Ansonic 12bit 433.92MHz
+ */
+const SubBruteProtocol subbrute_protocol_ansonic_12bit_433 = {
+    .frequency = 433920000,
+    .bits = 12,
+    .te = 0,
+    .repeat = 3,
+    .preset = FuriHalSubGhzPreset2FSKDev238Async,
+    .file = AnsonicFileProtocol};
+
+/**
+ * Ansonic 12bit 434.075MHz
+ */
+const SubBruteProtocol subbrute_protocol_ansonic_12bit_434 = {
+    .frequency = 434075000,
+    .bits = 12,
+    .te = 0,
+    .repeat = 3,
+    .preset = FuriHalSubGhzPreset2FSKDev238Async,
+    .file = AnsonicFileProtocol};
+
+/**
+ * Chamberlain 9bit 300MHz
+ */
+const SubBruteProtocol subbrute_protocol_chamberlain_9bit_300 = {
+    .frequency = 300000000,
+    .bits = 9,
+    .te = 0,
+    .repeat = 3,
+    .preset = FuriHalSubGhzPresetOok650Async,
+    .file = ChamberlainFileProtocol};
+
+/**
+ * Chamberlain 9bit 315MHz
+ */
+const SubBruteProtocol subbrute_protocol_chamberlain_9bit_315 = {
+    .frequency = 315000000,
+    .bits = 9,
+    .te = 0,
+    .repeat = 3,
+    .preset = FuriHalSubGhzPresetOok650Async,
+    .file = ChamberlainFileProtocol};
+
+/**
+ * Chamberlain 9bit 390MHz
+ */
+const SubBruteProtocol subbrute_protocol_chamberlain_9bit_390 = {
+    .frequency = 390000000,
+    .bits = 9,
+    .te = 0,
+    .repeat = 3,
+    .preset = FuriHalSubGhzPresetOok650Async,
+    .file = ChamberlainFileProtocol};
+
+/**
+ * Chamberlain 9bit 433MHz
+ */
+const SubBruteProtocol subbrute_protocol_chamberlain_9bit_433 = {
+    .frequency = 433920000,
+    .bits = 9,
+    .te = 0,
+    .repeat = 3,
+    .preset = FuriHalSubGhzPresetOok650Async,
+    .file = ChamberlainFileProtocol};
+
+/**
+ * Chamberlain 8bit 300MHz
+ */
+const SubBruteProtocol subbrute_protocol_chamberlain_8bit_300 = {
+    .frequency = 300000000,
+    .bits = 8,
+    .te = 0,
+    .repeat = 3,
+    .preset = FuriHalSubGhzPresetOok650Async,
+    .file = ChamberlainFileProtocol};
+
+/**
+ * Chamberlain 8bit 315MHz
+ */
+const SubBruteProtocol subbrute_protocol_chamberlain_8bit_315 = {
+    .frequency = 315000000,
+    .bits = 8,
+    .te = 0,
+    .repeat = 3,
+    .preset = FuriHalSubGhzPresetOok650Async,
+    .file = ChamberlainFileProtocol};
+
+/**
+ * Chamberlain 8bit 390MHz
+ */
+const SubBruteProtocol subbrute_protocol_chamberlain_8bit_390 = {
+    .frequency = 390000000,
+    .bits = 8,
+    .te = 0,
+    .repeat = 3,
+    .preset = FuriHalSubGhzPresetOok650Async,
+    .file = ChamberlainFileProtocol};
+
+/**
+ * Chamberlain 7bit 300MHz
+ */
+const SubBruteProtocol subbrute_protocol_chamberlain_7bit_300 = {
+    .frequency = 300000000,
+    .bits = 7,
+    .te = 0,
+    .repeat = 3,
+    .preset = FuriHalSubGhzPresetOok650Async,
+    .file = ChamberlainFileProtocol};
+
+/**
+ * Chamberlain 7bit 315MHz
+ */
+const SubBruteProtocol subbrute_protocol_chamberlain_7bit_315 = {
+    .frequency = 315000000,
+    .bits = 7,
+    .te = 0,
+    .repeat = 3,
+    .preset = FuriHalSubGhzPresetOok650Async,
+    .file = ChamberlainFileProtocol};
+
+/**
+ * Chamberlain 7bit 390MHz
+ */
+const SubBruteProtocol subbrute_protocol_chamberlain_7bit_390 = {
+    .frequency = 390000000,
+    .bits = 7,
+    .te = 0,
+    .repeat = 3,
+    .preset = FuriHalSubGhzPresetOok650Async,
+    .file = ChamberlainFileProtocol};
+
+/**
+ * Linear 10bit 300MHz
+ */
+const SubBruteProtocol subbrute_protocol_linear_10bit_300 = {
+    .frequency = 300000000,
+    .bits = 10,
+    .te = 0,
+    .repeat = 5,
+    .preset = FuriHalSubGhzPresetOok650Async,
+    .file = LinearFileProtocol};
+
+/**
+ * Linear 10bit 310MHz
+ */
+const SubBruteProtocol subbrute_protocol_linear_10bit_310 = {
+    .frequency = 310000000,
+    .bits = 10,
+    .te = 0,
+    .repeat = 5,
+    .preset = FuriHalSubGhzPresetOok650Async,
+    .file = LinearFileProtocol};
+
+/**
+ * Linear Delta 3 8bit 310MHz
+ */
+const SubBruteProtocol subbrute_protocol_linear_delta_8bit_310 = {
+    .frequency = 310000000,
+    .bits = 8,
+    .te = 0,
+    .repeat = 5,
+    .preset = FuriHalSubGhzPresetOok650Async,
+    .file = LinearDeltaFileProtocol};
+
+/**
+ * UNILARM 24bit 330MHz
+ */
+const SubBruteProtocol subbrute_protocol_unilarm_24bit_330 = {
+    .frequency = 330000000,
+    .bits = 25,
+    .te = 209,
+    .repeat = 4,
+    .preset = FuriHalSubGhzPresetOok650Async,
+    .file = UNILARMFileProtocol};
+
+/**
+ * UNILARM 24bit 433MHz
+ */
+const SubBruteProtocol subbrute_protocol_unilarm_24bit_433 = {
+    .frequency = 433920000,
+    .bits = 25,
+    .te = 209,
+    .repeat = 4,
+    .preset = FuriHalSubGhzPresetOok650Async,
+    .file = UNILARMFileProtocol};
+
+/**
+ * SMC5326 24bit 330MHz
+ */
+const SubBruteProtocol subbrute_protocol_smc5326_24bit_330 = {
+    .frequency = 330000000,
+    .bits = 25,
+    .te = 320,
+    .repeat = 4,
+    .preset = FuriHalSubGhzPresetOok650Async,
+    .file = SMC5326FileProtocol};
+
+/**
+ * SMC5326 24bit 433MHz
+ */
+const SubBruteProtocol subbrute_protocol_smc5326_24bit_433 = {
+    .frequency = 433920000,
+    .bits = 25,
+    .te = 320,
+    .repeat = 4,
+    .preset = FuriHalSubGhzPresetOok650Async,
+    .file = SMC5326FileProtocol};
+
+/**
+ * PT2260 (Princeton) 24bit 315MHz
+ */
+const SubBruteProtocol subbrute_protocol_pt2260_24bit_315 = {
+    .frequency = 315000000,
+    .bits = 24,
+    .te = 286,
+    .repeat = 4,
+    .preset = FuriHalSubGhzPresetOok650Async,
+    .file = PT2260FileProtocol};
+
+/**
+ * PT2260 (Princeton) 24bit 330MHz
+ */
+const SubBruteProtocol subbrute_protocol_pt2260_24bit_330 = {
+    .frequency = 330000000,
+    .bits = 24,
+    .te = 286,
+    .repeat = 4,
+    .preset = FuriHalSubGhzPresetOok650Async,
+    .file = PT2260FileProtocol};
+
+/**
+ * PT2260 (Princeton) 24bit 390MHz
+ */
+const SubBruteProtocol subbrute_protocol_pt2260_24bit_390 = {
+    .frequency = 390000000,
+    .bits = 24,
+    .te = 286,
+    .repeat = 4,
+    .preset = FuriHalSubGhzPresetOok650Async,
+    .file = PT2260FileProtocol};
+
+/**
+ * PT2260 (Princeton) 24bit 433MHz
+ */
+const SubBruteProtocol subbrute_protocol_pt2260_24bit_433 = {
+    .frequency = 433920000,
+    .bits = 24,
+    .te = 286,
+    .repeat = 4,
+    .preset = FuriHalSubGhzPresetOok650Async,
+    .file = PT2260FileProtocol};
+
+/**
+ * Holtek FM 12bit 433MHz
+ */
+const SubBruteProtocol subbrute_protocol_holtek_12bit_433 = {
+    .frequency = 433920000,
+    .bits = 12,
+    .te = 204,
+    .repeat = 4,
+    .preset = FuriHalSubGhzPreset2FSKDev476Async,
+    .file = HoltekFileProtocol};
+
+/**
+ * Holtek AM 12bit 433MHz
+ */
+const SubBruteProtocol subbrute_protocol_holtek_12bit_am_433 = {
+    .frequency = 433920000,
+    .bits = 12,
+    .te = 433,
+    .repeat = 3,
+    .preset = FuriHalSubGhzPresetOok650Async,
+    .file = HoltekFileProtocol};
+
+/**
+ * Holtek AM 12bit 315MHz
+ */
+const SubBruteProtocol subbrute_protocol_holtek_12bit_am_315 = {
+    .frequency = 315000000,
+    .bits = 12,
+    .te = 433,
+    .repeat = 3,
+    .preset = FuriHalSubGhzPresetOok650Async,
+    .file = HoltekFileProtocol};
+
+/**
+ * Holtek AM 12bit 868MHz
+ */
+const SubBruteProtocol subbrute_protocol_holtek_12bit_am_868 = {
+    .frequency = 868350000,
+    .bits = 12,
+    .te = 433,
+    .repeat = 3,
+    .preset = FuriHalSubGhzPresetOok650Async,
+    .file = HoltekFileProtocol};
+
+/**
+ * Holtek AM 12bit 915MHz
+ */
+const SubBruteProtocol subbrute_protocol_holtek_12bit_am_915 = {
+    .frequency = 915000000,
+    .bits = 12,
+    .te = 433,
+    .repeat = 3,
+    .preset = FuriHalSubGhzPresetOok650Async,
+    .file = HoltekFileProtocol};
+
+/**
+ * BF existing dump
+ */
+const SubBruteProtocol subbrute_protocol_load_file =
+    {0, 0, 0, 3, FuriHalSubGhzPresetOok650Async, UnknownFileProtocol};
+
+static const char* subbrute_protocol_names[] = {
+    [SubBruteAttackCAME12bit303] = "CAME 12bit 303MHz",
+    [SubBruteAttackCAME12bit307] = "CAME 12bit 307MHz",
+    [SubBruteAttackCAME12bit315] = "CAME 12bit 315MHz",
+    [SubBruteAttackCAME12bit433] = "CAME 12bit 433MHz",
+    [SubBruteAttackCAME12bit868] = "CAME 12bit 868MHz",
+    [SubBruteAttackNICE12bit433] = "NICE 12bit 433MHz",
+    [SubBruteAttackNICE12bit868] = "NICE 12bit 868MHz",
+    [SubBruteAttackAnsonic12bit433075] = "Ansonic 12bit 433.07MHz",
+    [SubBruteAttackAnsonic12bit433] = "Ansonic 12bit 433.92MHz",
+    [SubBruteAttackAnsonic12bit434] = "Ansonic 12bit 434.07MHz",
+    [SubBruteAttackHoltek12bitFM433] = "Holtek FM 12bit 433MHz",
+    [SubBruteAttackHoltek12bitAM433] = "Holtek AM 12bit 433MHz",
+    [SubBruteAttackHoltek12bitAM315] = "Holtek AM 12bit 315MHz",
+    [SubBruteAttackHoltek12bitAM868] = "Holtek AM 12bit 868MHz",
+    [SubBruteAttackHoltek12bitAM915] = "Holtek AM 12bit 915MHz",
+    [SubBruteAttackChamberlain9bit300] = "Chamberlain 9bit 300MHz",
+    [SubBruteAttackChamberlain9bit315] = "Chamberlain 9bit 315MHz",
+    [SubBruteAttackChamberlain9bit390] = "Chamberlain 9bit 390MHz",
+    [SubBruteAttackChamberlain9bit433] = "Chamberlain 9bit 433MHz",
+    [SubBruteAttackChamberlain8bit300] = "Chamberlain 8bit 300MHz",
+    [SubBruteAttackChamberlain8bit315] = "Chamberlain 8bit 315MHz",
+    [SubBruteAttackChamberlain8bit390] = "Chamberlain 8bit 390MHz",
+    [SubBruteAttackChamberlain7bit300] = "Chamberlain 7bit 300MHz",
+    [SubBruteAttackChamberlain7bit315] = "Chamberlain 7bit 315MHz",
+    [SubBruteAttackChamberlain7bit390] = "Chamberlain 7bit 390MHz",
+    [SubBruteAttackLinear10bit300] = "Linear 10bit 300MHz",
+    [SubBruteAttackLinear10bit310] = "Linear 10bit 310MHz",
+    [SubBruteAttackLinearDelta8bit310] = "LinearDelta3 8bit 310MHz",
+    [SubBruteAttackUNILARM24bit330] = "UNILARM 25bit 330MHz",
+    [SubBruteAttackUNILARM24bit433] = "UNILARM 25bit 433MHz",
+    [SubBruteAttackSMC532624bit330] = "SMC5326 25bit 330MHz",
+    [SubBruteAttackSMC532624bit433] = "SMC5326 25bit 433MHz",
+    [SubBruteAttackPT226024bit315] = "PT2260 24bit 315MHz",
+    [SubBruteAttackPT226024bit330] = "PT2260 24bit 330MHz",
+    [SubBruteAttackPT226024bit390] = "PT2260 24bit 390MHz",
+    [SubBruteAttackPT226024bit433] = "PT2260 24bit 433MHz",
+    [SubBruteAttackLoadFile] = "BF existing dump",
+    [SubBruteAttackTotalCount] = "Total Count",
+};
+
+static const char* subbrute_protocol_presets[] = {
+    [FuriHalSubGhzPresetIDLE] = "FuriHalSubGhzPresetIDLE",
+    [FuriHalSubGhzPresetOok270Async] = "FuriHalSubGhzPresetOok270Async",
+    [FuriHalSubGhzPresetOok650Async] = "FuriHalSubGhzPresetOok650Async",
+    [FuriHalSubGhzPreset2FSKDev238Async] = "FuriHalSubGhzPreset2FSKDev238Async",
+    [FuriHalSubGhzPreset2FSKDev476Async] = "FuriHalSubGhzPreset2FSKDev476Async",
+    [FuriHalSubGhzPresetMSK99_97KbAsync] = "FuriHalSubGhzPresetMSK99_97KbAsync",
+    [FuriHalSubGhzPresetGFSK9_99KbAsync] = "FuriHalSubGhzPresetGFSK9_99KbAsync",
+};
+
+const SubBruteProtocol* subbrute_protocol_registry[] = {
+    [SubBruteAttackCAME12bit303] = &subbrute_protocol_came_12bit_303,
+    [SubBruteAttackCAME12bit307] = &subbrute_protocol_came_12bit_307,
+    [SubBruteAttackCAME12bit315] = &subbrute_protocol_came_12bit_315,
+    [SubBruteAttackCAME12bit433] = &subbrute_protocol_came_12bit_433,
+    [SubBruteAttackCAME12bit868] = &subbrute_protocol_came_12bit_868,
+    [SubBruteAttackNICE12bit433] = &subbrute_protocol_nice_12bit_433,
+    [SubBruteAttackNICE12bit868] = &subbrute_protocol_nice_12bit_868,
+    [SubBruteAttackAnsonic12bit433075] = &subbrute_protocol_ansonic_12bit_433075,
+    [SubBruteAttackAnsonic12bit433] = &subbrute_protocol_ansonic_12bit_433,
+    [SubBruteAttackAnsonic12bit434] = &subbrute_protocol_ansonic_12bit_434,
+    [SubBruteAttackHoltek12bitFM433] = &subbrute_protocol_holtek_12bit_433,
+    [SubBruteAttackHoltek12bitAM433] = &subbrute_protocol_holtek_12bit_am_433,
+    [SubBruteAttackHoltek12bitAM315] = &subbrute_protocol_holtek_12bit_am_315,
+    [SubBruteAttackHoltek12bitAM868] = &subbrute_protocol_holtek_12bit_am_868,
+    [SubBruteAttackHoltek12bitAM915] = &subbrute_protocol_holtek_12bit_am_915,
+    [SubBruteAttackChamberlain9bit300] = &subbrute_protocol_chamberlain_9bit_300,
+    [SubBruteAttackChamberlain9bit315] = &subbrute_protocol_chamberlain_9bit_315,
+    [SubBruteAttackChamberlain9bit390] = &subbrute_protocol_chamberlain_9bit_390,
+    [SubBruteAttackChamberlain9bit433] = &subbrute_protocol_chamberlain_9bit_433,
+    [SubBruteAttackChamberlain8bit300] = &subbrute_protocol_chamberlain_8bit_300,
+    [SubBruteAttackChamberlain8bit315] = &subbrute_protocol_chamberlain_8bit_315,
+    [SubBruteAttackChamberlain8bit390] = &subbrute_protocol_chamberlain_8bit_390,
+    [SubBruteAttackChamberlain7bit300] = &subbrute_protocol_chamberlain_7bit_300,
+    [SubBruteAttackChamberlain7bit315] = &subbrute_protocol_chamberlain_7bit_315,
+    [SubBruteAttackChamberlain7bit390] = &subbrute_protocol_chamberlain_7bit_390,
+    [SubBruteAttackLinear10bit300] = &subbrute_protocol_linear_10bit_300,
+    [SubBruteAttackLinear10bit310] = &subbrute_protocol_linear_10bit_310,
+    [SubBruteAttackLinearDelta8bit310] = &subbrute_protocol_linear_delta_8bit_310,
+    [SubBruteAttackUNILARM24bit330] = &subbrute_protocol_unilarm_24bit_330,
+    [SubBruteAttackUNILARM24bit433] = &subbrute_protocol_unilarm_24bit_433,
+    [SubBruteAttackSMC532624bit330] = &subbrute_protocol_smc5326_24bit_330,
+    [SubBruteAttackSMC532624bit433] = &subbrute_protocol_smc5326_24bit_433,
+    [SubBruteAttackPT226024bit315] = &subbrute_protocol_pt2260_24bit_315,
+    [SubBruteAttackPT226024bit330] = &subbrute_protocol_pt2260_24bit_330,
+    [SubBruteAttackPT226024bit390] = &subbrute_protocol_pt2260_24bit_390,
+    [SubBruteAttackPT226024bit433] = &subbrute_protocol_pt2260_24bit_433,
+    [SubBruteAttackLoadFile] = &subbrute_protocol_load_file};
+
+static const char* subbrute_protocol_file_types[] = {
+    [CAMEFileProtocol] = "CAME",
+    [NICEFileProtocol] = "Nice FLO",
+    [ChamberlainFileProtocol] = "Cham_Code",
+    [LinearFileProtocol] = "Linear",
+    [LinearDeltaFileProtocol] = "LinearDelta3",
+    [PrincetonFileProtocol] = "Princeton",
+    [RAWFileProtocol] = "RAW",
+    [BETTFileProtocol] = "BETT",
+    [ClemsaFileProtocol] = "Clemsa",
+    [DoitrandFileProtocol] = "Doitrand",
+    [GateTXFileProtocol] = "GateTX",
+    [MagellanFileProtocol] = "Magellan",
+    [IntertechnoV3FileProtocol] = "Intertechno_V3",
+    [AnsonicFileProtocol] = "Ansonic",
+    [SMC5326FileProtocol] = "SMC5326",
+    [UNILARMFileProtocol] = "SMC5326",
+    [PT2260FileProtocol] = "Princeton",
+    [HoneywellFileProtocol] = "Honeywell",
+    [HoltekFileProtocol] = "Holtek_HT12X",
+    [UnknownFileProtocol] = "Unknown"};
+
+/**
+ * Values to not use less memory for packet parse operations
+ */
+static const char* subbrute_key_file_start_no_tail =
+    "Filetype: Flipper SubGhz Key File\nVersion: 1\nFrequency: %u\nPreset: %s\nProtocol: %s\nBit: %d\nKey: %s\n";
+static const char* subbrute_key_file_start_with_tail =
+    "Filetype: Flipper SubGhz Key File\nVersion: 1\nFrequency: %u\nPreset: %s\nProtocol: %s\nBit: %d\nKey: %s\nTE: %d\n";
+static const char* subbrute_key_small_no_tail = "Bit: %d\nKey: %s\nRepeat: %d\n";
+//static const char* subbrute_key_small_raw =
+//    "Filetype: Flipper SubGhz Key File\nVersion: 1\nFrequency: %u\nPreset: %s\nProtocol: %s\nBit: %d\n";
+static const char* subbrute_key_small_with_tail = "Bit: %d\nKey: %s\nTE: %d\nRepeat: %d\n";
+
+const char* subbrute_protocol_name(SubBruteAttacks index) {
+    return subbrute_protocol_names[index];
+}
+
+const SubBruteProtocol* subbrute_protocol(SubBruteAttacks index) {
+    return subbrute_protocol_registry[index];
+}
+
+uint8_t subbrute_protocol_repeats_count(SubBruteAttacks index) {
+    return subbrute_protocol_registry[index]->repeat;
+}
+
+const char* subbrute_protocol_preset(FuriHalSubGhzPreset preset) {
+    return subbrute_protocol_presets[preset];
+}
+
+const char* subbrute_protocol_file(SubBruteFileProtocol protocol) {
+    return subbrute_protocol_file_types[protocol];
+}
+
+FuriHalSubGhzPreset subbrute_protocol_convert_preset(FuriString* preset_name) {
+    for(size_t i = FuriHalSubGhzPresetIDLE; i < FuriHalSubGhzPresetCustom; i++) {
+        if(furi_string_cmp_str(preset_name, subbrute_protocol_presets[i]) == 0) {
+            return i;
+        }
+    }
+
+    return FuriHalSubGhzPresetIDLE;
+}
+
+SubBruteFileProtocol subbrute_protocol_file_protocol_name(FuriString* name) {
+    for(size_t i = CAMEFileProtocol; i < TotalFileProtocol - 1; i++) {
+        if(furi_string_cmp_str(name, subbrute_protocol_file_types[i]) == 0) {
+            return i;
+        }
+    }
+
+    return UnknownFileProtocol;
+}
+
+void subbrute_protocol_create_candidate_for_existing_file(
+    FuriString* candidate,
+    uint64_t step,
+    size_t bit_index,
+    uint64_t file_key,
+    bool two_bytes) {
+    uint8_t p[8];
+    for(int i = 0; i < 8; i++) {
+        p[i] = (uint8_t)(file_key >> 8 * (7 - i)) & 0xFF;
+    }
+    uint8_t low_byte = step & (0xff);
+    uint8_t high_byte = (step >> 8) & 0xff;
+
+    size_t size = sizeof(uint64_t);
+    for(size_t i = 0; i < size; i++) {
+        if(i == bit_index - 1 && two_bytes) {
+            furi_string_cat_printf(candidate, "%02X %02X", high_byte, low_byte);
+            i++;
+        } else if(i == bit_index) {
+            furi_string_cat_printf(candidate, "%02X", low_byte);
+        } else if(p[i] != 0) {
+            furi_string_cat_printf(candidate, "%02X", p[i]);
+        } else {
+            furi_string_cat_printf(candidate, "%s", "00");
+        }
+
+        if(i < size - 1) {
+            furi_string_push_back(candidate, ' ');
+        }
+    }
+
+#ifdef FURI_DEBUG
+    FURI_LOG_D(TAG, "file candidate: %s, step: %lld", furi_string_get_cstr(candidate), step);
+#endif
+}
+
+void subbrute_protocol_create_candidate_for_default(
+    FuriString* candidate,
+    SubBruteFileProtocol file,
+    uint64_t step) {
+    uint8_t p[8];
+    if(file == SMC5326FileProtocol) {
+        const uint8_t lut[] = {0x00, 0x02, 0x03}; // 00, 10, 11
+        const uint64_t gate1 = 0x01D5; // 111010101
+        //const uint8_t gate2 = 0x0175; // 101110101
+
+        uint64_t total = 0;
+        for(size_t j = 0; j < 8; j++) {
+            total |= lut[step % 3] << (2 * j);
+            double sub_step = (double)step / 3;
+            step = (uint64_t)floor(sub_step);
+        }
+        total <<= 9;
+        total |= gate1;
+
+        for(int i = 0; i < 8; i++) {
+            p[i] = (uint8_t)(total >> 8 * (7 - i)) & 0xFF;
+        }
+    } else if(file == UNILARMFileProtocol) {
+        const uint8_t lut[] = {0x00, 0x02, 0x03}; // 00, 10, 11
+        const uint64_t gate1 = 3 << 7;
+        //const uint8_t gate2 = 3 << 5;
+
+        uint64_t total = 0;
+        for(size_t j = 0; j < 8; j++) {
+            total |= lut[step % 3] << (2 * j);
+            double sub_step = (double)step / 3;
+            step = (uint64_t)floor(sub_step);
+        }
+        total <<= 9;
+        total |= gate1;
+
+        for(int i = 0; i < 8; i++) {
+            p[i] = (uint8_t)(total >> 8 * (7 - i)) & 0xFF;
+        }
+    } else if(file == PT2260FileProtocol) {
+        const uint8_t lut[] = {0x00, 0x01, 0x03}; // 00, 01, 11
+        const uint64_t button_open = 0x03; // 11
+        //const uint8_t button_lock = 0x0C; // 1100
+        //const uint8_t button_stop = 0x30; // 110000
+        //const uint8_t button_close = 0xC0; // 11000000
+
+        uint64_t total = 0;
+        for(size_t j = 0; j < 8; j++) {
+            total |= lut[step % 3] << (2 * j);
+            double sub_step = (double)step / 3;
+            step = (uint64_t)floor(sub_step);
+        }
+        total <<= 8;
+        total |= button_open;
+
+        for(int i = 0; i < 8; i++) {
+            p[i] = (uint8_t)(total >> 8 * (7 - i)) & 0xFF;
+        }
+    } else {
+        for(int i = 0; i < 8; i++) {
+            p[i] = (uint8_t)(step >> 8 * (7 - i)) & 0xFF;
+        }
+    }
+
+    size_t size = sizeof(uint64_t);
+    for(size_t i = 0; i < size; i++) {
+        if(p[i] != 0) {
+            furi_string_cat_printf(candidate, "%02X", p[i]);
+        } else {
+            furi_string_cat_printf(candidate, "%s", "00");
+        }
+
+        if(i < size - 1) {
+            furi_string_push_back(candidate, ' ');
+        }
+    }
+
+#ifdef FURI_DEBUG
+    FURI_LOG_D(TAG, "candidate: %s, step: %lld", furi_string_get_cstr(candidate), step);
+#endif
+}
+
+void subbrute_protocol_default_payload(
+    Stream* stream,
+    SubBruteFileProtocol file,
+    uint64_t step,
+    uint8_t bits,
+    uint32_t te,
+    uint8_t repeat) {
+    FuriString* candidate = furi_string_alloc();
+    subbrute_protocol_create_candidate_for_default(candidate, file, step);
+
+#ifdef FURI_DEBUG
+    FURI_LOG_D(
+        TAG,
+        "candidate: %s, step: %lld, repeat: %d, te: %s",
+        furi_string_get_cstr(candidate),
+        step,
+        repeat,
+        te ? "true" : "false");
+#endif
+    stream_clean(stream);
+    if(te) {
+        stream_write_format(
+            stream,
+            subbrute_key_small_with_tail,
+            bits,
+            furi_string_get_cstr(candidate),
+            te,
+            repeat);
+    } else {
+        stream_write_format(
+            stream, subbrute_key_small_no_tail, bits, furi_string_get_cstr(candidate), repeat);
+    }
+
+    furi_string_free(candidate);
+}
+
+void subbrute_protocol_file_payload(
+    Stream* stream,
+    uint64_t step,
+    uint8_t bits,
+    uint32_t te,
+    uint8_t repeat,
+    uint8_t bit_index,
+    uint64_t file_key,
+    bool two_bytes) {
+    FuriString* candidate = furi_string_alloc();
+    subbrute_protocol_create_candidate_for_existing_file(
+        candidate, step, bit_index, file_key, two_bytes);
+
+#ifdef FURI_DEBUG
+    FURI_LOG_D(
+        TAG,
+        "candidate: %s, step: %lld, repeat: %d, te: %s",
+        furi_string_get_cstr(candidate),
+        step,
+        repeat,
+        te ? "true" : "false");
+#endif
+    stream_clean(stream);
+
+    if(te) {
+        stream_write_format(
+            stream,
+            subbrute_key_small_with_tail,
+            bits,
+            furi_string_get_cstr(candidate),
+            te,
+            repeat);
+    } else {
+        stream_write_format(
+            stream, subbrute_key_small_no_tail, bits, furi_string_get_cstr(candidate), repeat);
+    }
+
+    furi_string_free(candidate);
+}
+
+void subbrute_protocol_default_generate_file(
+    Stream* stream,
+    uint32_t frequency,
+    FuriHalSubGhzPreset preset,
+    SubBruteFileProtocol file,
+    uint64_t step,
+    uint8_t bits,
+    uint32_t te) {
+    FuriString* candidate = furi_string_alloc();
+    subbrute_protocol_create_candidate_for_default(candidate, file, step);
+
+#ifdef FURI_DEBUG
+    FURI_LOG_D(TAG, "candidate: %s, step: %lld", furi_string_get_cstr(candidate), step);
+#endif
+    stream_clean(stream);
+
+    if(te) {
+        stream_write_format(
+            stream,
+            subbrute_key_file_start_with_tail,
+            frequency,
+            subbrute_protocol_preset(preset),
+            subbrute_protocol_file(file),
+            bits,
+            furi_string_get_cstr(candidate),
+            te);
+    } else {
+        stream_write_format(
+            stream,
+            subbrute_key_file_start_no_tail,
+            frequency,
+            subbrute_protocol_preset(preset),
+            subbrute_protocol_file(file),
+            bits,
+            furi_string_get_cstr(candidate));
+    }
+
+    furi_string_free(candidate);
+}
+
+void subbrute_protocol_file_generate_file(
+    Stream* stream,
+    uint32_t frequency,
+    FuriHalSubGhzPreset preset,
+    SubBruteFileProtocol file,
+    uint64_t step,
+    uint8_t bits,
+    uint32_t te,
+    uint8_t bit_index,
+    uint64_t file_key,
+    bool two_bytes) {
+    FuriString* candidate = furi_string_alloc();
+    // char subbrute_payload_byte[8];
+    //furi_string_set_str(candidate, file_key);
+    subbrute_protocol_create_candidate_for_existing_file(
+        candidate, step, bit_index, file_key, two_bytes);
+
+    stream_clean(stream);
+
+    if(te) {
+        stream_write_format(
+            stream,
+            subbrute_key_file_start_with_tail,
+            frequency,
+            subbrute_protocol_preset(preset),
+            subbrute_protocol_file(file),
+            bits,
+            furi_string_get_cstr(candidate),
+            te);
+    } else {
+        stream_write_format(
+            stream,
+            subbrute_key_file_start_no_tail,
+            frequency,
+            subbrute_protocol_preset(preset),
+            subbrute_protocol_file(file),
+            bits,
+            furi_string_get_cstr(candidate));
+    }
+
+    furi_string_free(candidate);
+}
+
+uint64_t
+    subbrute_protocol_calc_max_value(SubBruteAttacks attack_type, uint8_t bits, bool two_bytes) {
+    uint64_t max_value;
+    if(attack_type == SubBruteAttackLoadFile) {
+        max_value = two_bytes ? 0xFFFF : 0xFF;
+    } else if(
+        attack_type == SubBruteAttackSMC532624bit330 ||
+        attack_type == SubBruteAttackSMC532624bit433 ||
+        attack_type == SubBruteAttackUNILARM24bit330 ||
+        attack_type == SubBruteAttackUNILARM24bit433 ||
+        attack_type == SubBruteAttackPT226024bit315 ||
+        attack_type == SubBruteAttackPT226024bit330 ||
+        attack_type == SubBruteAttackPT226024bit390 ||
+        attack_type == SubBruteAttackPT226024bit433) {
+        max_value = 6561;
+    } else {
+        FuriString* max_value_s;
+        max_value_s = furi_string_alloc();
+        for(uint8_t i = 0; i < bits; i++) {
+            furi_string_cat_printf(max_value_s, "1");
+        }
+        max_value = (uint64_t)strtol(furi_string_get_cstr(max_value_s), NULL, 2);
+        furi_string_free(max_value_s);
+    }
+
+    return max_value;
+}

+ 128 - 0
subghz_bruteforcer/subbrute_protocols.h

@@ -0,0 +1,128 @@
+#pragma once
+
+#include <furi.h>
+#include <furi_hal_subghz.h>
+#include <core/string.h>
+#include <toolbox/stream/stream.h>
+
+#define SUBBRUTE_PROTOCOL_MAX_REPEATS 9
+
+typedef enum {
+    CAMEFileProtocol,
+    NICEFileProtocol,
+    ChamberlainFileProtocol,
+    LinearFileProtocol,
+    LinearDeltaFileProtocol,
+    PrincetonFileProtocol,
+    RAWFileProtocol,
+    BETTFileProtocol,
+    ClemsaFileProtocol,
+    DoitrandFileProtocol,
+    GateTXFileProtocol,
+    MagellanFileProtocol,
+    IntertechnoV3FileProtocol,
+    AnsonicFileProtocol,
+    SMC5326FileProtocol,
+    UNILARMFileProtocol,
+    PT2260FileProtocol,
+    HoneywellFileProtocol,
+    HoltekFileProtocol,
+    UnknownFileProtocol,
+    TotalFileProtocol,
+} SubBruteFileProtocol;
+
+typedef enum {
+    SubBruteAttackCAME12bit303,
+    SubBruteAttackCAME12bit307,
+    SubBruteAttackCAME12bit315,
+    SubBruteAttackCAME12bit433,
+    SubBruteAttackCAME12bit868,
+    SubBruteAttackNICE12bit433,
+    SubBruteAttackNICE12bit868,
+    SubBruteAttackAnsonic12bit433075,
+    SubBruteAttackAnsonic12bit433,
+    SubBruteAttackAnsonic12bit434,
+    SubBruteAttackHoltek12bitFM433,
+    SubBruteAttackHoltek12bitAM433,
+    SubBruteAttackHoltek12bitAM315,
+    SubBruteAttackHoltek12bitAM868,
+    SubBruteAttackHoltek12bitAM915,
+    SubBruteAttackChamberlain9bit300,
+    SubBruteAttackChamberlain9bit315,
+    SubBruteAttackChamberlain9bit390,
+    SubBruteAttackChamberlain9bit433,
+    SubBruteAttackChamberlain8bit300,
+    SubBruteAttackChamberlain8bit315,
+    SubBruteAttackChamberlain8bit390,
+    SubBruteAttackChamberlain7bit300,
+    SubBruteAttackChamberlain7bit315,
+    SubBruteAttackChamberlain7bit390,
+    SubBruteAttackLinear10bit300,
+    SubBruteAttackLinear10bit310,
+    SubBruteAttackLinearDelta8bit310,
+    SubBruteAttackUNILARM24bit330,
+    SubBruteAttackUNILARM24bit433,
+    SubBruteAttackSMC532624bit330,
+    SubBruteAttackSMC532624bit433,
+    SubBruteAttackPT226024bit315,
+    SubBruteAttackPT226024bit330,
+    SubBruteAttackPT226024bit390,
+    SubBruteAttackPT226024bit433,
+    SubBruteAttackLoadFile,
+    SubBruteAttackTotalCount,
+} SubBruteAttacks;
+
+typedef struct {
+    uint32_t frequency;
+    uint8_t bits;
+    uint32_t te;
+    uint8_t repeat;
+    FuriHalSubGhzPreset preset;
+    SubBruteFileProtocol file;
+} SubBruteProtocol;
+
+const SubBruteProtocol* subbrute_protocol(SubBruteAttacks index);
+const char* subbrute_protocol_preset(FuriHalSubGhzPreset preset);
+const char* subbrute_protocol_file(SubBruteFileProtocol protocol);
+FuriHalSubGhzPreset subbrute_protocol_convert_preset(FuriString* preset_name);
+SubBruteFileProtocol subbrute_protocol_file_protocol_name(FuriString* name);
+uint8_t subbrute_protocol_repeats_count(SubBruteAttacks index);
+const char* subbrute_protocol_name(SubBruteAttacks index);
+
+void subbrute_protocol_default_payload(
+    Stream* stream,
+    SubBruteFileProtocol file,
+    uint64_t step,
+    uint8_t bits,
+    uint32_t te,
+    uint8_t repeat);
+void subbrute_protocol_file_payload(
+    Stream* stream,
+    uint64_t step,
+    uint8_t bits,
+    uint32_t te,
+    uint8_t repeat,
+    uint8_t bit_index,
+    uint64_t file_key,
+    bool two_bytes);
+void subbrute_protocol_default_generate_file(
+    Stream* stream,
+    uint32_t frequency,
+    FuriHalSubGhzPreset preset,
+    SubBruteFileProtocol file,
+    uint64_t step,
+    uint8_t bits,
+    uint32_t te);
+void subbrute_protocol_file_generate_file(
+    Stream* stream,
+    uint32_t frequency,
+    FuriHalSubGhzPreset preset,
+    SubBruteFileProtocol file,
+    uint64_t step,
+    uint8_t bits,
+    uint32_t te,
+    uint8_t bit_index,
+    uint64_t file_key,
+    bool two_bytes);
+uint64_t
+    subbrute_protocol_calc_max_value(SubBruteAttacks attack_type, uint8_t bits, bool two_bytes);

+ 150 - 0
subghz_bruteforcer/subbrute_settings.c

@@ -0,0 +1,150 @@
+#include "subbrute_settings.h"
+#include "subbrute_i.h"
+
+#define TAG "SubBruteSettings"
+
+#define SUBBRUTE_SETTINGS_FILE_TYPE "Sub-GHz BruteForcer Settings File"
+#define SUBBRUTE_SETTINGS_FILE_VERSION 1
+#define SUBBRUTE_SETTINGS_PATH APP_DATA_PATH("bruteforcer.settings")
+
+#define SUBBRUTE_FIELD_LAST_INDEX "LastIndex"
+#define SUBBRUTE_FIELD_REPEAT_VALUES "RepeatValue"
+
+SubBruteSettings* subbrute_settings_alloc(void) {
+    SubBruteSettings* instance = malloc(sizeof(SubBruteSettings));
+    return instance;
+}
+
+void subbrute_settings_free(SubBruteSettings* instance) {
+    furi_assert(instance);
+    free(instance);
+}
+
+void subbrute_settings_load(SubBruteSettings* instance) {
+    furi_assert(instance);
+
+    Storage* storage = furi_record_open(RECORD_STORAGE);
+    FlipperFormat* fff_data_file = flipper_format_file_alloc(storage);
+
+    uint32_t temp_last_index = 0;
+    uint8_t temp_repeat_values[SubBruteAttackTotalCount] = {0};
+    bool was_read_last_index = false;
+    bool was_read_repeat_values = false;
+
+    storage_common_migrate(
+        storage, EXT_PATH("subghz-bruteforcer.settings"), SUBBRUTE_SETTINGS_PATH);
+
+    if(FSE_OK == storage_sd_status(storage) && SUBBRUTE_SETTINGS_PATH &&
+       flipper_format_file_open_existing(fff_data_file, SUBBRUTE_SETTINGS_PATH)) {
+        was_read_last_index = flipper_format_read_uint32(
+            fff_data_file, SUBBRUTE_FIELD_LAST_INDEX, (uint32_t*)&temp_last_index, 1);
+        was_read_repeat_values = flipper_format_read_hex(
+            fff_data_file,
+            SUBBRUTE_FIELD_REPEAT_VALUES,
+            temp_repeat_values,
+            SubBruteAttackTotalCount);
+    } else {
+        FURI_LOG_E(TAG, "Error open file %s", SUBBRUTE_SETTINGS_PATH);
+    }
+
+    if(was_read_last_index && temp_last_index < SubBruteAttackTotalCount) {
+        instance->last_index = temp_last_index;
+    } else {
+        FURI_LOG_W(TAG, "Last used index not found or can't be used!");
+        instance->last_index = (uint32_t)SubBruteAttackCAME12bit433;
+    }
+    if(was_read_repeat_values) {
+        for(size_t i = 0; i < SubBruteAttackTotalCount; i++) {
+            uint8_t protocol_count = subbrute_protocol_repeats_count(i);
+            uint8_t max_protocol_count = protocol_count * 3;
+            if(temp_repeat_values[i] < protocol_count) {
+                instance->repeat_values[i] = protocol_count;
+            } else if(temp_repeat_values[i] > max_protocol_count) {
+                instance->repeat_values[i] = max_protocol_count;
+            } else {
+                instance->repeat_values[i] = temp_repeat_values[i];
+            }
+        }
+    } else {
+        FURI_LOG_W(TAG, "Last used repeat values can't be used!");
+        for(size_t i = 0; i < SubBruteAttackTotalCount; i++) {
+            instance->repeat_values[i] = subbrute_protocol_repeats_count(i);
+        }
+    }
+
+    flipper_format_file_close(fff_data_file);
+    flipper_format_free(fff_data_file);
+    furi_record_close(RECORD_STORAGE);
+}
+
+bool subbrute_settings_save(SubBruteSettings* instance) {
+    furi_assert(instance);
+
+    bool saved = false;
+    Storage* storage = furi_record_open(RECORD_STORAGE);
+    FlipperFormat* file = flipper_format_file_alloc(storage);
+
+    do {
+        if(FSE_OK != storage_sd_status(storage)) {
+            break;
+        }
+        // Open file
+        if(!flipper_format_file_open_always(file, SUBBRUTE_SETTINGS_PATH)) {
+            break;
+        }
+        // Write header
+        if(!flipper_format_write_header_cstr(
+               file, SUBBRUTE_SETTINGS_FILE_TYPE, SUBBRUTE_SETTINGS_FILE_VERSION)) {
+            break;
+        }
+        if(!flipper_format_insert_or_update_uint32(
+               file, SUBBRUTE_FIELD_LAST_INDEX, &instance->last_index, 1)) {
+            break;
+        }
+
+        if(!flipper_format_insert_or_update_hex(
+               file,
+               SUBBRUTE_FIELD_REPEAT_VALUES,
+               instance->repeat_values,
+               SubBruteAttackTotalCount)) {
+            break;
+        }
+        saved = true;
+        break;
+    } while(true);
+
+    if(!saved) {
+        FURI_LOG_E(TAG, "Error save file %s", SUBBRUTE_SETTINGS_PATH);
+    }
+
+    flipper_format_file_close(file);
+    flipper_format_free(file);
+    furi_record_close(RECORD_STORAGE);
+
+    return saved;
+}
+
+void subbrute_settings_set_value(SubBruteSettings* instance, SubBruteAttacks index, uint8_t value) {
+    furi_assert(instance);
+
+    instance->repeat_values[index] = value;
+}
+uint8_t subbrute_settings_get_value(SubBruteSettings* instance, SubBruteAttacks index) {
+    furi_assert(instance);
+
+    return instance->repeat_values[index];
+}
+
+void subbrute_settings_set_repeats(SubBruteSettings* instance, const uint8_t* repeated_values) {
+    furi_assert(instance);
+
+    for(size_t i = 0; i < SubBruteAttackTotalCount; i++) {
+        instance->repeat_values[i] = repeated_values[i];
+    }
+}
+
+uint8_t subbrute_settings_get_current_repeats(SubBruteSettings* instance) {
+    furi_assert(instance);
+
+    return instance->repeat_values[instance->last_index];
+}

+ 21 - 0
subghz_bruteforcer/subbrute_settings.h

@@ -0,0 +1,21 @@
+#pragma once
+
+#include <furi_hal.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <storage/storage.h>
+#include "subbrute_protocols.h"
+
+typedef struct {
+    uint8_t repeat_values[SubBruteAttackTotalCount];
+    uint32_t last_index;
+} SubBruteSettings;
+
+SubBruteSettings* subbrute_settings_alloc(void);
+void subbrute_settings_free(SubBruteSettings* instance);
+void subbrute_settings_load(SubBruteSettings* instance);
+bool subbrute_settings_save(SubBruteSettings* instance);
+void subbrute_settings_set_value(SubBruteSettings* instance, SubBruteAttacks index, uint8_t value);
+uint8_t subbrute_settings_get_value(SubBruteSettings* instance, SubBruteAttacks index);
+void subbrute_settings_set_repeats(SubBruteSettings* instance, const uint8_t* repeated_values);
+uint8_t subbrute_settings_get_current_repeats(SubBruteSettings* instance);

+ 346 - 0
subghz_bruteforcer/views/subbrute_attack_view.c

@@ -0,0 +1,346 @@
+#include "subbrute_attack_view.h"
+#include "../subbrute_i.h"
+#include "../helpers/gui_top_buttons.h"
+
+#include <input/input.h>
+#include <gui/elements.h>
+#include <gui/icon_animation.h>
+#include <subghz_bruteforcer_icons.h>
+
+#include <assets_icons.h>
+
+#define TAG "SubBruteAttackView"
+
+struct SubBruteAttackView {
+    View* view;
+    SubBruteAttackViewCallback callback;
+    void* context;
+    SubBruteAttacks attack_type;
+    uint64_t max_value;
+    uint64_t current_step;
+    bool is_attacking;
+    // uint8_t extra_repeats;
+};
+
+typedef struct {
+    SubBruteAttacks attack_type;
+    uint64_t max_value;
+    uint64_t current_step;
+    uint8_t repeat_count;
+    bool is_attacking;
+    IconAnimation* icon;
+} SubBruteAttackViewModel;
+
+void subbrute_attack_view_set_callback(
+    SubBruteAttackView* instance,
+    SubBruteAttackViewCallback callback,
+    void* context) {
+    furi_assert(instance);
+    furi_assert(callback);
+
+    instance->callback = callback;
+    instance->context = context;
+}
+
+bool subbrute_attack_view_input(InputEvent* event, void* context) {
+    furi_assert(event);
+    furi_assert(context);
+    SubBruteAttackView* instance = context;
+#ifdef FURI_DEBUG
+    FURI_LOG_D(TAG, "InputKey: %d", event->key);
+#endif
+
+    if(event->key == InputKeyBack && event->type == InputTypeShort) {
+        instance->is_attacking = false;
+        with_view_model(
+            instance->view,
+            SubBruteAttackViewModel * model,
+            { model->is_attacking = false; },
+            true);
+
+        instance->callback(SubBruteCustomEventTypeBackPressed, instance->context);
+        return true;
+    }
+
+    bool update = false;
+
+    if(!instance->is_attacking) {
+        if(event->type == InputTypeShort && event->key == InputKeyOk) {
+#ifdef FURI_DEBUG
+            FURI_LOG_D(TAG, "InputKey: %d OK", event->key);
+#endif
+            instance->is_attacking = true;
+            instance->callback(SubBruteCustomEventTypeTransmitStarted, instance->context);
+            update = true;
+        } else if(event->key == InputKeyUp && event->type == InputTypeShort) {
+            instance->callback(SubBruteCustomEventTypeSaveFile, instance->context);
+            update = true;
+        } else if(event->key == InputKeyUp && event->type == InputTypeLong) {
+            instance->callback(SubBruteCustomEventTypeExtraSettings, instance->context);
+            update = true;
+        } else if(event->key == InputKeyDown) {
+            instance->callback(SubBruteCustomEventTypeTransmitCustom, instance->context);
+            update = true;
+        } else if(event->type == InputTypeShort) {
+            if(event->key == InputKeyLeft) {
+                instance->callback(SubBruteCustomEventTypeChangeStepDown, instance->context);
+            } else if(event->key == InputKeyRight) {
+                instance->callback(SubBruteCustomEventTypeChangeStepUp, instance->context);
+            }
+            update = true;
+        } else if(event->type == InputTypeRepeat) {
+            if(event->key == InputKeyLeft) {
+                instance->callback(SubBruteCustomEventTypeChangeStepDownMore, instance->context);
+            } else if(event->key == InputKeyRight) {
+                instance->callback(SubBruteCustomEventTypeChangeStepUpMore, instance->context);
+            }
+            update = true;
+        }
+    } else {
+        // ATTACK Mode!
+        if((event->type == InputTypeShort || event->type == InputTypeRepeat) &&
+           (event->key == InputKeyOk || event->key == InputKeyBack)) {
+            instance->is_attacking = false;
+            instance->callback(SubBruteCustomEventTypeTransmitNotStarted, instance->context);
+
+            update = true;
+        }
+    }
+
+    if(update) {
+        with_view_model(
+            instance->view,
+            SubBruteAttackViewModel * model,
+            {
+                if(model->is_attacking != instance->is_attacking) {
+                    if(instance->is_attacking) {
+                        icon_animation_stop(model->icon);
+                        icon_animation_start(model->icon);
+                    } else {
+                        icon_animation_stop(model->icon);
+                    }
+                }
+
+                model->attack_type = instance->attack_type;
+                model->max_value = instance->max_value;
+                model->current_step = instance->current_step;
+                model->is_attacking = instance->is_attacking;
+            },
+            update);
+    }
+
+    return update;
+}
+
+SubBruteAttackView* subbrute_attack_view_alloc() {
+    SubBruteAttackView* instance = malloc(sizeof(SubBruteAttackView));
+
+    instance->view = view_alloc();
+    view_allocate_model(instance->view, ViewModelTypeLocking, sizeof(SubBruteAttackViewModel));
+    view_set_context(instance->view, instance);
+
+    with_view_model(
+        instance->view,
+        SubBruteAttackViewModel * model,
+        {
+            model->icon = icon_animation_alloc(&A_Sub1ghz_14);
+            view_tie_icon_animation(instance->view, model->icon);
+        },
+        false);
+
+    view_set_draw_callback(instance->view, (ViewDrawCallback)subbrute_attack_view_draw);
+    view_set_input_callback(instance->view, subbrute_attack_view_input);
+    view_set_enter_callback(instance->view, subbrute_attack_view_enter);
+    view_set_exit_callback(instance->view, subbrute_attack_view_exit);
+
+    instance->attack_type = SubBruteAttackTotalCount;
+    instance->max_value = 0x00;
+    instance->current_step = 0;
+    instance->is_attacking = false;
+
+    return instance;
+}
+
+void subbrute_attack_view_enter(void* context) {
+    furi_assert(context);
+    SubBruteAttackView* instance = context;
+    with_view_model(
+        instance->view,
+        SubBruteAttackViewModel * model,
+        {
+            if(model->is_attacking) {
+                icon_animation_start(model->icon);
+            }
+        },
+        true);
+}
+
+void subbrute_attack_view_free(SubBruteAttackView* instance) {
+    furi_assert(instance);
+
+    with_view_model(
+        instance->view,
+        SubBruteAttackViewModel * model,
+        { icon_animation_free(model->icon); },
+        false);
+
+    view_free(instance->view);
+    free(instance);
+}
+
+View* subbrute_attack_view_get_view(SubBruteAttackView* instance) {
+    furi_assert(instance);
+    return instance->view;
+}
+
+void subbrute_attack_view_set_current_step(SubBruteAttackView* instance, uint64_t current_step) {
+    furi_assert(instance);
+#ifdef FURI_DEBUG
+    //FURI_LOG_D(TAG, "Set step: %d", current_step);
+#endif
+    instance->current_step = current_step;
+    with_view_model(
+        instance->view,
+        SubBruteAttackViewModel * model,
+        { model->current_step = current_step; },
+        true);
+}
+
+// We need to call init every time, because not every time we calls enter
+// normally, call enter only once
+void subbrute_attack_view_init_values(
+    SubBruteAttackView* instance,
+    uint8_t index,
+    uint64_t max_value,
+    uint64_t current_step,
+    bool is_attacking,
+    uint8_t extra_repeats) {
+#ifdef FURI_DEBUG
+    FURI_LOG_I(
+        TAG,
+        "INIT, attack_type: %d, max_value: %lld, current_step: %lld, extra_repeats: %d",
+        index,
+        max_value,
+        current_step,
+        extra_repeats);
+#endif
+    instance->attack_type = index;
+    instance->max_value = max_value;
+    instance->current_step = current_step;
+    instance->is_attacking = is_attacking;
+    // instance->extra_repeats = extra_repeats;
+
+    with_view_model(
+        instance->view,
+        SubBruteAttackViewModel * model,
+        {
+            model->max_value = max_value;
+            model->attack_type = index;
+            model->current_step = current_step;
+            model->is_attacking = is_attacking;
+            model->repeat_count = extra_repeats;
+            if(is_attacking) {
+                icon_animation_start(model->icon);
+            } else {
+                icon_animation_stop(model->icon);
+            }
+        },
+        true);
+}
+
+void subbrute_attack_view_exit(void* context) {
+    furi_assert(context);
+    SubBruteAttackView* instance = context;
+#ifdef FURI_DEBUG
+    FURI_LOG_D(TAG, "subbrute_attack_view_exit");
+#endif
+    with_view_model(
+        instance->view,
+        SubBruteAttackViewModel * model,
+        { icon_animation_stop(model->icon); },
+        false);
+}
+
+void subbrute_attack_view_draw(Canvas* canvas, void* context) {
+    furi_assert(context);
+    SubBruteAttackViewModel* model = (SubBruteAttackViewModel*)context;
+    char buffer[64];
+
+    const char* attack_name = NULL;
+    attack_name = subbrute_protocol_name(model->attack_type);
+
+    // Title
+    if(model->is_attacking) {
+        canvas_set_color(canvas, ColorBlack);
+        canvas_set_font(canvas, FontSecondary);
+        canvas_draw_str_aligned(canvas, 64, 2, AlignCenter, AlignTop, attack_name);
+    }
+
+    // Current Step / Max value
+    const uint8_t y_frequency = 17;
+    if(model->max_value > 9999) {
+        canvas_set_font(canvas, FontBigNumbers);
+        snprintf(buffer, sizeof(buffer), "%05d/", (int)model->current_step);
+        canvas_draw_str_aligned(canvas, 5, y_frequency, AlignLeft, AlignTop, buffer);
+
+        // Second part with another font, because BigNumber is out of screen bounds
+        canvas_set_font(canvas, FontPrimary);
+        snprintf(buffer, sizeof(buffer), "%05d", (int)model->max_value);
+        canvas_draw_str_aligned(canvas, 107, y_frequency + 13, AlignRight, AlignBottom, buffer);
+    } else if(model->max_value <= 0xFF) {
+        canvas_set_font(canvas, FontBigNumbers);
+        snprintf(
+            buffer, sizeof(buffer), "%03d/%03d", (int)model->current_step, (int)model->max_value);
+        canvas_draw_str_aligned(canvas, 64, y_frequency, AlignCenter, AlignTop, buffer);
+    } else {
+        canvas_set_font(canvas, FontBigNumbers);
+        snprintf(
+            buffer, sizeof(buffer), "%04d/%04d", (int)model->current_step, (int)model->max_value);
+        canvas_draw_str_aligned(canvas, 64, y_frequency, AlignCenter, AlignTop, buffer);
+    }
+    canvas_set_font(canvas, FontSecondary);
+
+    memset(buffer, 0, sizeof(buffer));
+    if(!model->is_attacking) {
+        canvas_set_color(canvas, ColorBlack);
+        canvas_set_font(canvas, FontSecondary);
+        canvas_draw_str_aligned(canvas, 64, 44, AlignCenter, AlignBottom, attack_name);
+
+        snprintf(
+            buffer,
+            sizeof(buffer),
+            "x%d",
+            model->repeat_count); // + subbrute_protocol_repeats_count(model->attack_type));
+        canvas_draw_str_aligned(canvas, 60, 6, AlignCenter, AlignCenter, buffer);
+
+        elements_button_left(canvas, "-1");
+        elements_button_right(canvas, "+1");
+        elements_button_center(canvas, "Start");
+        elements_button_top_left(canvas, "Save");
+        elements_button_top_right(canvas, "Resend");
+    } else {
+        // canvas_draw_icon_animation
+        const uint8_t icon_h_offset = 0;
+        const uint8_t icon_width_with_offset =
+            icon_animation_get_width(model->icon) + icon_h_offset;
+        const uint8_t icon_v_offset = icon_animation_get_height(model->icon); // + vertical_offset;
+        const uint8_t x = canvas_width(canvas);
+        const uint8_t y = canvas_height(canvas);
+        canvas_draw_icon_animation(
+            canvas, x - icon_width_with_offset, y - icon_v_offset, model->icon);
+        // Progress bar
+        // Resolution: 128x64 px
+        float progress_value = (float)model->current_step / (float)model->max_value;
+        elements_progress_bar(canvas, 8, 37, 110, progress_value > 1 ? 1 : progress_value);
+
+        snprintf(
+            buffer,
+            sizeof(buffer),
+            "x%d",
+            model->repeat_count); // + subbrute_protocol_repeats_count(model->attack_type));
+        canvas_draw_str(canvas, 4, y - 8, buffer);
+        canvas_draw_str(canvas, 4, y - 1, "repeats");
+
+        elements_button_center(canvas, "Stop");
+    }
+}

+ 25 - 0
subghz_bruteforcer/views/subbrute_attack_view.h

@@ -0,0 +1,25 @@
+#pragma once
+
+#include "../subbrute_custom_event.h"
+#include <gui/view.h>
+#include <input/input.h>
+#include <gui/elements.h>
+
+typedef void (*SubBruteAttackViewCallback)(SubBruteCustomEvent event, void* context);
+typedef struct SubBruteAttackView SubBruteAttackView;
+
+void subbrute_attack_view_set_callback(
+    SubBruteAttackView* instance,
+    SubBruteAttackViewCallback callback,
+    void* context);
+SubBruteAttackView* subbrute_attack_view_alloc();
+void subbrute_attack_view_free(SubBruteAttackView* instance);
+View* subbrute_attack_view_get_view(SubBruteAttackView* instance);
+void subbrute_attack_view_set_current_step(SubBruteAttackView* instance, uint64_t current_step);
+void subbrute_attack_view_init_values(
+    SubBruteAttackView* instance,
+    uint8_t index,
+    uint64_t max_value,
+    uint64_t current_step,
+    bool is_attacking,
+    uint8_t extra_repeats);

+ 488 - 0
subghz_bruteforcer/views/subbrute_main_view.c

@@ -0,0 +1,488 @@
+#include "subbrute_main_view.h"
+#include "../subbrute_i.h"
+#include "../helpers/gui_top_buttons.h"
+
+#include <input/input.h>
+#include <gui/elements.h>
+
+#define STATUS_BAR_Y_SHIFT 14
+#define TAG "SubBruteMainView"
+
+#define ITEMS_ON_SCREEN 3
+#define ITEMS_INTERVAL 1
+#define ITEM_WIDTH 14
+#define ITEM_Y 27
+#define ITEM_HEIGHT 13
+#define TEXT_X 6
+#define TEXT_Y 37
+#define TEXT_INTERVAL 3
+#define TEXT_WIDTH 12
+#define ITEM_FRAME_RADIUS 2
+
+struct SubBruteMainView {
+    View* view;
+    SubBruteMainViewCallback callback;
+    void* context;
+    uint8_t index;
+    bool is_select_byte;
+    bool two_bytes;
+    uint64_t key_from_file;
+    uint8_t repeat_values[SubBruteAttackTotalCount];
+    uint8_t window_position;
+};
+
+typedef struct {
+    uint8_t index;
+    uint8_t repeat_values[SubBruteAttackTotalCount];
+    uint8_t window_position;
+    bool is_select_byte;
+    bool two_bytes;
+    uint64_t key_from_file;
+} SubBruteMainViewModel;
+
+void subbrute_main_view_set_callback(
+    SubBruteMainView* instance,
+    SubBruteMainViewCallback callback,
+    void* context) {
+    furi_assert(instance);
+    furi_assert(callback);
+
+    instance->callback = callback;
+    instance->context = context;
+}
+
+void subbrute_main_view_center_displayed_key(
+    Canvas* canvas,
+    uint64_t key,
+    uint8_t index,
+    bool two_bytes) {
+    uint8_t text_x = TEXT_X;
+    uint8_t item_x = TEXT_X - ITEMS_INTERVAL;
+    canvas_set_font(canvas, FontSecondary);
+
+    for(int i = 0; i < 8; i++) {
+        char current_value[3] = {0};
+        uint8_t byte_value = (uint8_t)(key >> 8 * (7 - i)) & 0xFF;
+        snprintf(current_value, sizeof(current_value), "%02X", byte_value);
+
+        // For two bytes we need to select prev location
+        if(!two_bytes && i == index) {
+            canvas_set_color(canvas, ColorBlack);
+            canvas_draw_rbox(
+                canvas, item_x - 1, ITEM_Y, ITEM_WIDTH + 1, ITEM_HEIGHT, ITEM_FRAME_RADIUS);
+            canvas_set_color(canvas, ColorWhite);
+            canvas_draw_str(canvas, text_x, TEXT_Y, current_value);
+        } else if(two_bytes && (i == index || i == index - 1)) {
+            if(i == index) {
+                canvas_set_color(canvas, ColorBlack);
+                canvas_draw_rbox(
+                    canvas,
+                    item_x - ITEMS_INTERVAL - ITEM_WIDTH - 1,
+                    ITEM_Y,
+                    ITEM_WIDTH * 2 + ITEMS_INTERVAL * 2 + 1,
+                    ITEM_HEIGHT,
+                    ITEM_FRAME_RADIUS);
+
+                canvas_set_color(canvas, ColorWhite);
+                canvas_draw_str(canvas, text_x, TEXT_Y, current_value);
+
+                // Redraw prev element with white
+                memset(current_value, 0, sizeof(current_value));
+                byte_value = (uint8_t)(key >> 8 * (7 - i + 1)) & 0xFF;
+                snprintf(current_value, sizeof(current_value), "%02X", byte_value);
+                canvas_draw_str(
+                    canvas, text_x - (TEXT_WIDTH + TEXT_INTERVAL), TEXT_Y, current_value);
+            } else {
+                canvas_set_color(canvas, ColorWhite);
+                canvas_draw_str(canvas, text_x, TEXT_Y, current_value);
+            }
+        } else {
+            canvas_set_color(canvas, ColorBlack);
+            canvas_draw_str(canvas, text_x, TEXT_Y, current_value);
+        }
+        text_x = text_x + TEXT_WIDTH + TEXT_INTERVAL;
+        item_x = item_x + ITEM_WIDTH + ITEMS_INTERVAL;
+    }
+
+    // Return normal color
+    canvas_set_color(canvas, ColorBlack);
+}
+
+void subbrute_main_view_draw_is_byte_selected(Canvas* canvas, SubBruteMainViewModel* model) {
+#ifdef FURI_DEBUG
+    //FURI_LOG_D(TAG, "key_from_file: %s", model->key_from_file);
+#endif
+    //char msg_index[18];
+    //snprintf(msg_index, sizeof(msg_index), "Field index: %d", model->index);
+    canvas_set_font(canvas, FontSecondary);
+    canvas_draw_str_aligned(
+        canvas, 64, 17, AlignCenter, AlignTop, "Please select values to calc:");
+
+    subbrute_main_view_center_displayed_key(
+        canvas, model->key_from_file, model->index, model->two_bytes);
+    //const char* line = furi_string_get_cstr(menu_items);
+    //canvas_set_font(canvas, FontSecondary);
+    //canvas_draw_str_aligned(
+    //    canvas, 64, 37, AlignCenter, AlignTop, furi_string_get_cstr(menu_items));
+
+    elements_button_center(canvas, "Select");
+    if(model->index > 0) {
+        elements_button_left(canvas, " ");
+    }
+    if(model->index < 7) {
+        elements_button_right(canvas, " ");
+    }
+    // Switch to another mode
+    if(model->two_bytes) {
+        elements_button_top_left(canvas, "One byte");
+    } else {
+        elements_button_top_left(canvas, "Two bytes");
+    }
+}
+
+void subbrute_main_view_draw_is_ordinary_selected(Canvas* canvas, SubBruteMainViewModel* model) {
+    uint16_t screen_width = canvas_width(canvas);
+    uint16_t screen_height = canvas_height(canvas);
+
+    // Title
+    canvas_set_font(canvas, FontPrimary);
+    canvas_draw_box(canvas, 0, 0, canvas_width(canvas), STATUS_BAR_Y_SHIFT);
+    canvas_invert_color(canvas);
+    canvas_draw_str_aligned(canvas, 64, 3, AlignCenter, AlignTop, SUBBRUTEFORCER_VER);
+    canvas_invert_color(canvas);
+
+    // Menu
+    canvas_set_color(canvas, ColorBlack);
+    canvas_set_font(canvas, FontSecondary);
+    const uint8_t item_height = 16;
+    const uint8_t string_height_offset = 9;
+
+#ifdef FURI_DEBUG
+    //FURI_LOG_D(TAG, "window_position: %d, index: %d", model->window_position, model->index);
+#endif
+    for(size_t position = 0; position < SubBruteAttackTotalCount; ++position) {
+        uint8_t item_position = position - model->window_position;
+
+        if(item_position < ITEMS_ON_SCREEN) {
+            if(model->index == position) {
+                canvas_draw_str_aligned(
+                    canvas,
+                    3,
+                    string_height_offset + (item_position * item_height) + STATUS_BAR_Y_SHIFT,
+                    AlignLeft,
+                    AlignCenter,
+                    subbrute_protocol_name(position));
+
+                elements_frame(
+                    canvas, 1, 1 + (item_position * item_height) + STATUS_BAR_Y_SHIFT, 124, 15);
+            } else {
+                canvas_draw_str_aligned(
+                    canvas,
+                    4,
+                    string_height_offset + (item_position * item_height) + STATUS_BAR_Y_SHIFT,
+                    AlignLeft,
+                    AlignCenter,
+                    subbrute_protocol_name(position));
+            }
+
+            uint8_t current_repeat_count = model->repeat_values[position];
+            uint8_t min_repeat_count = subbrute_protocol_repeats_count(position);
+
+            if(current_repeat_count > min_repeat_count) {
+#ifdef FW_ORIGIN_Official
+                canvas_set_font(canvas, FontSecondary);
+#else
+                canvas_set_font(canvas, FontBatteryPercent);
+#endif
+                char buffer[10];
+                snprintf(buffer, sizeof(buffer), "x%d", current_repeat_count);
+                uint8_t temp_x_offset_repeats =
+                    current_repeat_count <= SUBBRUTE_PROTOCOL_MAX_REPEATS ? 15 : 18;
+
+                canvas_draw_str_aligned(
+                    canvas,
+                    screen_width - temp_x_offset_repeats,
+                    string_height_offset + (item_position * item_height) + STATUS_BAR_Y_SHIFT,
+                    AlignLeft,
+                    AlignCenter,
+                    buffer);
+                canvas_set_font(canvas, FontSecondary);
+            }
+        }
+    }
+
+    elements_scrollbar_pos(
+        canvas,
+        screen_width,
+        STATUS_BAR_Y_SHIFT + 2,
+        screen_height - STATUS_BAR_Y_SHIFT,
+        model->index,
+        SubBruteAttackTotalCount);
+}
+
+void subbrute_main_view_draw(Canvas* canvas, SubBruteMainViewModel* model) {
+    if(model->is_select_byte) {
+        subbrute_main_view_draw_is_byte_selected(canvas, model);
+    } else {
+        subbrute_main_view_draw_is_ordinary_selected(canvas, model);
+    }
+}
+
+bool subbrute_main_view_input_file_protocol(InputEvent* event, SubBruteMainView* instance) {
+    bool updated = false;
+    if(event->key == InputKeyLeft) {
+        if((instance->index > 0 && !instance->two_bytes) ||
+           (instance->two_bytes && instance->index > 1)) {
+            instance->index--;
+        }
+        updated = true;
+    } else if(event->key == InputKeyRight) {
+        if(instance->index < 7) {
+            instance->index++;
+        }
+        updated = true;
+    } else if(event->key == InputKeyUp) {
+        instance->two_bytes = !instance->two_bytes;
+        // Because index is changing
+        if(instance->two_bytes && instance->index < 7) {
+            instance->index++;
+        }
+        // instance->callback(
+        //     instance->two_bytes ? SubBruteCustomEventTypeChangeStepUp :
+        //                           SubBruteCustomEventTypeChangeStepDown,
+        //     instance->context);
+
+        updated = true;
+    } else if(event->key == InputKeyOk) {
+        instance->callback(SubBruteCustomEventTypeIndexSelected, instance->context);
+        updated = true;
+    }
+    return updated;
+}
+
+bool subbrute_main_view_input_ordinary_protocol(
+    InputEvent* event,
+    SubBruteMainView* instance,
+    bool is_short) {
+    const uint8_t min_value = 0;
+    const uint8_t correct_total = SubBruteAttackTotalCount - 1;
+    uint8_t index = instance->index;
+    uint8_t min_repeats = subbrute_protocol_repeats_count(index);
+    uint8_t max_repeats = min_repeats * 3;
+    uint8_t current_repeats = instance->repeat_values[index];
+
+    bool updated = false;
+    if(event->key == InputKeyUp && is_short) {
+        if(index == min_value) {
+            instance->index = correct_total;
+        } else {
+            instance->index = CLAMP(index - 1, correct_total, min_value);
+        }
+        //instance->repeat_values = 0;
+        updated = true;
+    } else if(event->key == InputKeyDown && is_short) {
+        if(index == correct_total) {
+            instance->index = min_value;
+        } else {
+            instance->index = CLAMP(index + 1, correct_total, min_value);
+        }
+        //instance->repeat_values = 0;
+        updated = true;
+    } else if(event->key == InputKeyLeft && is_short) {
+        instance->repeat_values[index] = CLAMP(current_repeats - 1, max_repeats, min_repeats);
+
+        updated = true;
+    } else if(event->key == InputKeyRight && is_short) {
+        instance->repeat_values[index] = CLAMP(current_repeats + 1, max_repeats, min_repeats);
+
+        updated = true;
+    } else if(event->key == InputKeyOk && is_short) {
+        if(index == SubBruteAttackLoadFile) {
+            instance->callback(SubBruteCustomEventTypeLoadFile, instance->context);
+        } else {
+            instance->callback(SubBruteCustomEventTypeMenuSelected, instance->context);
+        }
+        updated = true;
+    }
+
+    if(updated) {
+        instance->window_position = instance->index;
+        if(instance->window_position > 0) {
+            instance->window_position -= 1;
+        }
+
+        if(SubBruteAttackTotalCount <= ITEMS_ON_SCREEN) {
+            instance->window_position = 0;
+        } else {
+            if(instance->window_position >= (SubBruteAttackTotalCount - ITEMS_ON_SCREEN)) {
+                instance->window_position = (SubBruteAttackTotalCount - ITEMS_ON_SCREEN);
+            }
+        }
+    }
+
+    return updated;
+}
+
+bool subbrute_main_view_input(InputEvent* event, void* context) {
+    furi_assert(event);
+    furi_assert(context);
+
+    SubBruteMainView* instance = context;
+
+    if(event->key == InputKeyBack && event->type == InputTypeShort) {
+#ifdef FURI_DEBUG
+        FURI_LOG_I(TAG, "InputKey: BACK");
+#endif
+        instance->callback(SubBruteCustomEventTypeBackPressed, instance->context);
+        return false;
+    }
+
+#ifdef FURI_DEBUG
+    FURI_LOG_D(
+        TAG,
+        "InputKey: %d, extra_repeats: %d",
+        event->key,
+        instance->repeat_values[instance->index]);
+#endif
+
+    bool updated = false;
+    bool is_short = (event->type == InputTypeShort) || (event->type == InputTypeRepeat);
+
+    if(instance->is_select_byte) {
+        if(is_short) {
+            updated = subbrute_main_view_input_file_protocol(event, instance);
+        }
+    } else {
+        updated = subbrute_main_view_input_ordinary_protocol(event, instance, is_short);
+    }
+
+    if(updated) {
+        with_view_model(
+            instance->view,
+            SubBruteMainViewModel * model,
+            {
+                model->index = instance->index;
+                model->window_position = instance->window_position;
+                model->key_from_file = instance->key_from_file;
+                model->is_select_byte = instance->is_select_byte;
+                model->two_bytes = instance->two_bytes;
+                model->repeat_values[model->index] = instance->repeat_values[instance->index];
+            },
+            true);
+    }
+
+    return updated;
+}
+
+void subbrute_main_view_enter(void* context) {
+    furi_assert(context);
+}
+
+void subbrute_main_view_exit(void* context) {
+    furi_assert(context);
+}
+
+SubBruteMainView* subbrute_main_view_alloc() {
+    SubBruteMainView* instance = malloc(sizeof(SubBruteMainView));
+    instance->view = view_alloc();
+    view_allocate_model(instance->view, ViewModelTypeLocking, sizeof(SubBruteMainViewModel));
+    view_set_context(instance->view, instance);
+    view_set_draw_callback(instance->view, (ViewDrawCallback)subbrute_main_view_draw);
+    view_set_input_callback(instance->view, subbrute_main_view_input);
+    view_set_enter_callback(instance->view, subbrute_main_view_enter);
+    view_set_exit_callback(instance->view, subbrute_main_view_exit);
+
+    instance->index = 0;
+    instance->window_position = 0;
+    instance->key_from_file = 0;
+    instance->is_select_byte = false;
+    instance->two_bytes = false;
+
+    with_view_model(
+        instance->view,
+        SubBruteMainViewModel * model,
+        {
+            model->index = instance->index;
+            model->window_position = instance->window_position;
+            model->key_from_file = instance->key_from_file;
+            model->is_select_byte = instance->is_select_byte;
+            model->two_bytes = instance->two_bytes;
+        },
+        true);
+
+    return instance;
+}
+
+void subbrute_main_view_free(SubBruteMainView* instance) {
+    furi_assert(instance);
+
+    view_free(instance->view);
+    free(instance);
+}
+
+View* subbrute_main_view_get_view(SubBruteMainView* instance) {
+    furi_assert(instance);
+    return instance->view;
+}
+
+void subbrute_main_view_set_index(
+    SubBruteMainView* instance,
+    uint8_t idx,
+    const uint8_t* repeats,
+    bool is_select_byte,
+    bool two_bytes,
+    uint64_t key_from_file) {
+    furi_assert(instance);
+    furi_assert(idx < SubBruteAttackTotalCount);
+#ifdef FURI_DEBUG
+    FURI_LOG_I(TAG, "Set index: %d, is_select_byte: %d", idx, is_select_byte);
+#endif
+    for(size_t i = 0; i < SubBruteAttackTotalCount; i++) {
+        instance->repeat_values[i] = repeats[i];
+    }
+    instance->is_select_byte = is_select_byte;
+    instance->two_bytes = two_bytes;
+    instance->key_from_file = key_from_file;
+    instance->index = idx;
+    instance->window_position = idx;
+
+    if(!is_select_byte) {
+        if(instance->window_position > 0) {
+            instance->window_position -= 1;
+        }
+
+        if(instance->window_position >= (SubBruteAttackTotalCount - ITEMS_ON_SCREEN)) {
+            instance->window_position = (SubBruteAttackTotalCount - ITEMS_ON_SCREEN);
+        }
+    }
+
+    with_view_model(
+        instance->view,
+        SubBruteMainViewModel * model,
+        {
+            model->index = instance->index;
+            model->window_position = instance->window_position;
+            model->key_from_file = instance->key_from_file;
+            model->is_select_byte = instance->is_select_byte;
+            model->two_bytes = instance->two_bytes;
+            for(size_t i = 0; i < SubBruteAttackTotalCount; i++) {
+                model->repeat_values[i] = repeats[i];
+            }
+        },
+        true);
+}
+
+SubBruteAttacks subbrute_main_view_get_index(SubBruteMainView* instance) {
+    furi_assert(instance);
+    return instance->index;
+}
+
+const uint8_t* subbrute_main_view_get_repeats(SubBruteMainView* instance) {
+    furi_assert(instance);
+    return instance->repeat_values;
+}
+
+bool subbrute_main_view_get_two_bytes(SubBruteMainView* instance) {
+    furi_assert(instance);
+    return instance->two_bytes;
+}

+ 33 - 0
subghz_bruteforcer/views/subbrute_main_view.h

@@ -0,0 +1,33 @@
+#pragma once
+
+#include "../subbrute_custom_event.h"
+#include "../subbrute_protocols.h"
+#include <gui/view.h>
+#include <input/input.h>
+#include <gui/elements.h>
+
+typedef void (*SubBruteMainViewCallback)(SubBruteCustomEvent event, void* context);
+typedef struct SubBruteMainView SubBruteMainView;
+
+void subbrute_main_view_set_callback(
+    SubBruteMainView* instance,
+    SubBruteMainViewCallback callback,
+    void* context);
+
+SubBruteMainView* subbrute_main_view_alloc();
+void subbrute_main_view_free(SubBruteMainView* instance);
+View* subbrute_main_view_get_view(SubBruteMainView* instance);
+void subbrute_main_view_set_index(
+    SubBruteMainView* instance,
+    uint8_t idx,
+    const uint8_t* repeats,
+    bool is_select_byte,
+    bool two_bytes,
+    uint64_t key_from_file);
+SubBruteAttacks subbrute_main_view_get_index(SubBruteMainView* instance);
+const uint8_t* subbrute_main_view_get_repeats(SubBruteMainView* instance);
+bool subbrute_main_view_get_two_bytes(SubBruteMainView* instance);
+void subbrute_attack_view_enter(void* context);
+void subbrute_attack_view_exit(void* context);
+bool subbrute_attack_view_input(InputEvent* event, void* context);
+void subbrute_attack_view_draw(Canvas* canvas, void* context);