subbrute_protocols.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829
  1. #include "subbrute_protocols.h"
  2. #include "math.h"
  3. #include <string.h>
  4. #define TAG "SubBruteProtocols"
  5. /**
  6. * CAME 12bit 303MHz
  7. */
  8. const SubBruteProtocol subbrute_protocol_came_12bit_303 = {
  9. .frequency = 303875000,
  10. .bits = 12,
  11. .te = 0,
  12. .repeat = 3,
  13. .preset = FuriHalSubGhzPresetOok650Async,
  14. .file = CAMEFileProtocol};
  15. /**
  16. * CAME 12bit 307MHz
  17. */
  18. const SubBruteProtocol subbrute_protocol_came_12bit_307 = {
  19. .frequency = 307800000,
  20. .bits = 12,
  21. .te = 0,
  22. .repeat = 3,
  23. .preset = FuriHalSubGhzPresetOok650Async,
  24. .file = CAMEFileProtocol};
  25. /**
  26. * CAME 12bit 315MHz
  27. */
  28. const SubBruteProtocol subbrute_protocol_came_12bit_315 = {
  29. .frequency = 315000000,
  30. .bits = 12,
  31. .te = 0,
  32. .repeat = 3,
  33. .preset = FuriHalSubGhzPresetOok650Async,
  34. .file = CAMEFileProtocol};
  35. /**
  36. * CAME 12bit 433MHz
  37. */
  38. const SubBruteProtocol subbrute_protocol_came_12bit_433 = {
  39. .frequency = 433920000,
  40. .bits = 12,
  41. .te = 0,
  42. .repeat = 3,
  43. .preset = FuriHalSubGhzPresetOok650Async,
  44. .file = CAMEFileProtocol};
  45. /**
  46. * CAME 12bit 868MHz
  47. */
  48. const SubBruteProtocol subbrute_protocol_came_12bit_868 = {
  49. .frequency = 868350000,
  50. .bits = 12,
  51. .te = 0,
  52. .repeat = 3,
  53. .preset = FuriHalSubGhzPresetOok650Async,
  54. .file = CAMEFileProtocol};
  55. /**
  56. * NICE 12bit 433MHz
  57. */
  58. const SubBruteProtocol subbrute_protocol_nice_12bit_433 = {
  59. .frequency = 433920000,
  60. .bits = 12,
  61. .te = 0,
  62. .repeat = 3,
  63. .preset = FuriHalSubGhzPresetOok650Async,
  64. .file = NICEFileProtocol};
  65. /**
  66. * NICE 12bit 868MHz
  67. */
  68. const SubBruteProtocol subbrute_protocol_nice_12bit_868 = {
  69. .frequency = 868350000,
  70. .bits = 12,
  71. .te = 0,
  72. .repeat = 3,
  73. .preset = FuriHalSubGhzPresetOok650Async,
  74. .file = NICEFileProtocol};
  75. /**
  76. * Ansonic 12bit 433.075MHz
  77. */
  78. const SubBruteProtocol subbrute_protocol_ansonic_12bit_433075 = {
  79. .frequency = 433075000,
  80. .bits = 12,
  81. .te = 0,
  82. .repeat = 3,
  83. .preset = FuriHalSubGhzPreset2FSKDev238Async,
  84. .file = AnsonicFileProtocol};
  85. /**
  86. * Ansonic 12bit 433.92MHz
  87. */
  88. const SubBruteProtocol subbrute_protocol_ansonic_12bit_433 = {
  89. .frequency = 433920000,
  90. .bits = 12,
  91. .te = 0,
  92. .repeat = 3,
  93. .preset = FuriHalSubGhzPreset2FSKDev238Async,
  94. .file = AnsonicFileProtocol};
  95. /**
  96. * Ansonic 12bit 434.075MHz
  97. */
  98. const SubBruteProtocol subbrute_protocol_ansonic_12bit_434 = {
  99. .frequency = 434075000,
  100. .bits = 12,
  101. .te = 0,
  102. .repeat = 3,
  103. .preset = FuriHalSubGhzPreset2FSKDev238Async,
  104. .file = AnsonicFileProtocol};
  105. /**
  106. * Chamberlain 9bit 300MHz
  107. */
  108. const SubBruteProtocol subbrute_protocol_chamberlain_9bit_300 = {
  109. .frequency = 300000000,
  110. .bits = 9,
  111. .te = 0,
  112. .repeat = 3,
  113. .preset = FuriHalSubGhzPresetOok650Async,
  114. .file = ChamberlainFileProtocol};
  115. /**
  116. * Chamberlain 9bit 315MHz
  117. */
  118. const SubBruteProtocol subbrute_protocol_chamberlain_9bit_315 = {
  119. .frequency = 315000000,
  120. .bits = 9,
  121. .te = 0,
  122. .repeat = 3,
  123. .preset = FuriHalSubGhzPresetOok650Async,
  124. .file = ChamberlainFileProtocol};
  125. /**
  126. * Chamberlain 9bit 390MHz
  127. */
  128. const SubBruteProtocol subbrute_protocol_chamberlain_9bit_390 = {
  129. .frequency = 390000000,
  130. .bits = 9,
  131. .te = 0,
  132. .repeat = 3,
  133. .preset = FuriHalSubGhzPresetOok650Async,
  134. .file = ChamberlainFileProtocol};
  135. /**
  136. * Chamberlain 9bit 433MHz
  137. */
  138. const SubBruteProtocol subbrute_protocol_chamberlain_9bit_433 = {
  139. .frequency = 433920000,
  140. .bits = 9,
  141. .te = 0,
  142. .repeat = 3,
  143. .preset = FuriHalSubGhzPresetOok650Async,
  144. .file = ChamberlainFileProtocol};
  145. /**
  146. * Chamberlain 8bit 300MHz
  147. */
  148. const SubBruteProtocol subbrute_protocol_chamberlain_8bit_300 = {
  149. .frequency = 300000000,
  150. .bits = 8,
  151. .te = 0,
  152. .repeat = 3,
  153. .preset = FuriHalSubGhzPresetOok650Async,
  154. .file = ChamberlainFileProtocol};
  155. /**
  156. * Chamberlain 8bit 315MHz
  157. */
  158. const SubBruteProtocol subbrute_protocol_chamberlain_8bit_315 = {
  159. .frequency = 315000000,
  160. .bits = 8,
  161. .te = 0,
  162. .repeat = 3,
  163. .preset = FuriHalSubGhzPresetOok650Async,
  164. .file = ChamberlainFileProtocol};
  165. /**
  166. * Chamberlain 8bit 390MHz
  167. */
  168. const SubBruteProtocol subbrute_protocol_chamberlain_8bit_390 = {
  169. .frequency = 390000000,
  170. .bits = 8,
  171. .te = 0,
  172. .repeat = 3,
  173. .preset = FuriHalSubGhzPresetOok650Async,
  174. .file = ChamberlainFileProtocol};
  175. /**
  176. * Chamberlain 7bit 300MHz
  177. */
  178. const SubBruteProtocol subbrute_protocol_chamberlain_7bit_300 = {
  179. .frequency = 300000000,
  180. .bits = 7,
  181. .te = 0,
  182. .repeat = 3,
  183. .preset = FuriHalSubGhzPresetOok650Async,
  184. .file = ChamberlainFileProtocol};
  185. /**
  186. * Chamberlain 7bit 315MHz
  187. */
  188. const SubBruteProtocol subbrute_protocol_chamberlain_7bit_315 = {
  189. .frequency = 315000000,
  190. .bits = 7,
  191. .te = 0,
  192. .repeat = 3,
  193. .preset = FuriHalSubGhzPresetOok650Async,
  194. .file = ChamberlainFileProtocol};
  195. /**
  196. * Chamberlain 7bit 390MHz
  197. */
  198. const SubBruteProtocol subbrute_protocol_chamberlain_7bit_390 = {
  199. .frequency = 390000000,
  200. .bits = 7,
  201. .te = 0,
  202. .repeat = 3,
  203. .preset = FuriHalSubGhzPresetOok650Async,
  204. .file = ChamberlainFileProtocol};
  205. /**
  206. * Linear 10bit 300MHz
  207. */
  208. const SubBruteProtocol subbrute_protocol_linear_10bit_300 = {
  209. .frequency = 300000000,
  210. .bits = 10,
  211. .te = 0,
  212. .repeat = 5,
  213. .preset = FuriHalSubGhzPresetOok650Async,
  214. .file = LinearFileProtocol};
  215. /**
  216. * Linear 10bit 310MHz
  217. */
  218. const SubBruteProtocol subbrute_protocol_linear_10bit_310 = {
  219. .frequency = 310000000,
  220. .bits = 10,
  221. .te = 0,
  222. .repeat = 5,
  223. .preset = FuriHalSubGhzPresetOok650Async,
  224. .file = LinearFileProtocol};
  225. /**
  226. * Linear Delta 3 8bit 310MHz
  227. */
  228. const SubBruteProtocol subbrute_protocol_linear_delta_8bit_310 = {
  229. .frequency = 310000000,
  230. .bits = 8,
  231. .te = 0,
  232. .repeat = 5,
  233. .preset = FuriHalSubGhzPresetOok650Async,
  234. .file = LinearDeltaFileProtocol};
  235. /**
  236. * UNILARM 24bit 330MHz
  237. */
  238. const SubBruteProtocol subbrute_protocol_unilarm_24bit_330 = {
  239. .frequency = 330000000,
  240. .bits = 25,
  241. .te = 209,
  242. .repeat = 5,
  243. .preset = FuriHalSubGhzPresetOok650Async,
  244. .file = UNILARMFileProtocol};
  245. /**
  246. * UNILARM 24bit 433MHz
  247. */
  248. const SubBruteProtocol subbrute_protocol_unilarm_24bit_433 = {
  249. .frequency = 433920000,
  250. .bits = 25,
  251. .te = 209,
  252. .repeat = 5,
  253. .preset = FuriHalSubGhzPresetOok650Async,
  254. .file = UNILARMFileProtocol};
  255. /**
  256. * SMC5326 24bit 330MHz
  257. */
  258. const SubBruteProtocol subbrute_protocol_smc5326_24bit_330 = {
  259. .frequency = 330000000,
  260. .bits = 25,
  261. .te = 320,
  262. .repeat = 5,
  263. .preset = FuriHalSubGhzPresetOok650Async,
  264. .file = SMC5326FileProtocol};
  265. /**
  266. * SMC5326 24bit 433MHz
  267. */
  268. const SubBruteProtocol subbrute_protocol_smc5326_24bit_433 = {
  269. .frequency = 433920000,
  270. .bits = 25,
  271. .te = 320,
  272. .repeat = 5,
  273. .preset = FuriHalSubGhzPresetOok650Async,
  274. .file = SMC5326FileProtocol};
  275. /**
  276. * PT2260 (Princeton) 24bit 315MHz
  277. */
  278. const SubBruteProtocol subbrute_protocol_pt2260_24bit_315 = {
  279. .frequency = 315000000,
  280. .bits = 24,
  281. .te = 286,
  282. .repeat = 5,
  283. .preset = FuriHalSubGhzPresetOok650Async,
  284. .file = PT2260FileProtocol};
  285. /**
  286. * PT2260 (Princeton) 24bit 330MHz
  287. */
  288. const SubBruteProtocol subbrute_protocol_pt2260_24bit_330 = {
  289. .frequency = 330000000,
  290. .bits = 24,
  291. .te = 286,
  292. .repeat = 5,
  293. .preset = FuriHalSubGhzPresetOok650Async,
  294. .file = PT2260FileProtocol};
  295. /**
  296. * PT2260 (Princeton) 24bit 390MHz
  297. */
  298. const SubBruteProtocol subbrute_protocol_pt2260_24bit_390 = {
  299. .frequency = 390000000,
  300. .bits = 24,
  301. .te = 286,
  302. .repeat = 5,
  303. .preset = FuriHalSubGhzPresetOok650Async,
  304. .file = PT2260FileProtocol};
  305. /**
  306. * PT2260 (Princeton) 24bit 433MHz
  307. */
  308. const SubBruteProtocol subbrute_protocol_pt2260_24bit_433 = {
  309. .frequency = 433920000,
  310. .bits = 24,
  311. .te = 286,
  312. .repeat = 5,
  313. .preset = FuriHalSubGhzPresetOok650Async,
  314. .file = PT2260FileProtocol};
  315. /**
  316. * Holtek FM 12bit 433MHz
  317. */
  318. const SubBruteProtocol subbrute_protocol_holtek_12bit_433 = {
  319. .frequency = 433920000,
  320. .bits = 12,
  321. .te = 204,
  322. .repeat = 4,
  323. .preset = FuriHalSubGhzPreset2FSKDev476Async,
  324. .file = HoltekFileProtocol};
  325. /**
  326. * BF existing dump
  327. */
  328. const SubBruteProtocol subbrute_protocol_load_file =
  329. {0, 0, 0, 3, FuriHalSubGhzPresetOok650Async, UnknownFileProtocol};
  330. static const char* subbrute_protocol_names[] = {
  331. [SubBruteAttackCAME12bit303] = "CAME 12bit 303MHz",
  332. [SubBruteAttackCAME12bit307] = "CAME 12bit 307MHz",
  333. [SubBruteAttackCAME12bit315] = "CAME 12bit 315MHz",
  334. [SubBruteAttackCAME12bit433] = "CAME 12bit 433MHz",
  335. [SubBruteAttackCAME12bit868] = "CAME 12bit 868MHz",
  336. [SubBruteAttackNICE12bit433] = "NICE 12bit 433MHz",
  337. [SubBruteAttackNICE12bit868] = "NICE 12bit 868MHz",
  338. [SubBruteAttackAnsonic12bit433075] = "Ansonic 12bit 433.07MHz",
  339. [SubBruteAttackAnsonic12bit433] = "Ansonic 12bit 433.92MHz",
  340. [SubBruteAttackAnsonic12bit434] = "Ansonic 12bit 434.07MHz",
  341. [SubBruteAttackHoltek12bit433] = "Holtek FM 12bit 433MHz",
  342. [SubBruteAttackChamberlain9bit300] = "Chamberlain 9bit 300MHz",
  343. [SubBruteAttackChamberlain9bit315] = "Chamberlain 9bit 315MHz",
  344. [SubBruteAttackChamberlain9bit390] = "Chamberlain 9bit 390MHz",
  345. [SubBruteAttackChamberlain9bit433] = "Chamberlain 9bit 433MHz",
  346. [SubBruteAttackChamberlain8bit300] = "Chamberlain 8bit 300MHz",
  347. [SubBruteAttackChamberlain8bit315] = "Chamberlain 8bit 315MHz",
  348. [SubBruteAttackChamberlain8bit390] = "Chamberlain 8bit 390MHz",
  349. [SubBruteAttackChamberlain7bit300] = "Chamberlain 7bit 300MHz",
  350. [SubBruteAttackChamberlain7bit315] = "Chamberlain 7bit 315MHz",
  351. [SubBruteAttackChamberlain7bit390] = "Chamberlain 7bit 390MHz",
  352. [SubBruteAttackLinear10bit300] = "Linear 10bit 300MHz",
  353. [SubBruteAttackLinear10bit310] = "Linear 10bit 310MHz",
  354. [SubBruteAttackLinearDelta8bit310] = "LinearDelta3 8bit 310MHz",
  355. [SubBruteAttackUNILARM24bit330] = "UNILARM 25bit 330MHz",
  356. [SubBruteAttackUNILARM24bit433] = "UNILARM 25bit 433MHz",
  357. [SubBruteAttackSMC532624bit330] = "SMC5326 25bit 330MHz",
  358. [SubBruteAttackSMC532624bit433] = "SMC5326 25bit 433MHz",
  359. [SubBruteAttackPT226024bit315] = "PT2260 24bit 315MHz",
  360. [SubBruteAttackPT226024bit330] = "PT2260 24bit 330MHz",
  361. [SubBruteAttackPT226024bit390] = "PT2260 24bit 390MHz",
  362. [SubBruteAttackPT226024bit433] = "PT2260 24bit 433MHz",
  363. [SubBruteAttackLoadFile] = "BF existing dump",
  364. [SubBruteAttackTotalCount] = "Total Count",
  365. };
  366. static const char* subbrute_protocol_presets[] = {
  367. [FuriHalSubGhzPresetIDLE] = "FuriHalSubGhzPresetIDLE",
  368. [FuriHalSubGhzPresetOok270Async] = "FuriHalSubGhzPresetOok270Async",
  369. [FuriHalSubGhzPresetOok650Async] = "FuriHalSubGhzPresetOok650Async",
  370. [FuriHalSubGhzPreset2FSKDev238Async] = "FuriHalSubGhzPreset2FSKDev238Async",
  371. [FuriHalSubGhzPreset2FSKDev476Async] = "FuriHalSubGhzPreset2FSKDev476Async",
  372. [FuriHalSubGhzPresetMSK99_97KbAsync] = "FuriHalSubGhzPresetMSK99_97KbAsync",
  373. [FuriHalSubGhzPresetGFSK9_99KbAsync] = "FuriHalSubGhzPresetGFSK9_99KbAsync",
  374. };
  375. const SubBruteProtocol* subbrute_protocol_registry[] = {
  376. [SubBruteAttackCAME12bit303] = &subbrute_protocol_came_12bit_303,
  377. [SubBruteAttackCAME12bit307] = &subbrute_protocol_came_12bit_307,
  378. [SubBruteAttackCAME12bit315] = &subbrute_protocol_came_12bit_315,
  379. [SubBruteAttackCAME12bit433] = &subbrute_protocol_came_12bit_433,
  380. [SubBruteAttackCAME12bit868] = &subbrute_protocol_came_12bit_868,
  381. [SubBruteAttackNICE12bit433] = &subbrute_protocol_nice_12bit_433,
  382. [SubBruteAttackNICE12bit868] = &subbrute_protocol_nice_12bit_868,
  383. [SubBruteAttackAnsonic12bit433075] = &subbrute_protocol_ansonic_12bit_433075,
  384. [SubBruteAttackAnsonic12bit433] = &subbrute_protocol_ansonic_12bit_433,
  385. [SubBruteAttackAnsonic12bit434] = &subbrute_protocol_ansonic_12bit_434,
  386. [SubBruteAttackHoltek12bit433] = &subbrute_protocol_holtek_12bit_433,
  387. [SubBruteAttackChamberlain9bit300] = &subbrute_protocol_chamberlain_9bit_300,
  388. [SubBruteAttackChamberlain9bit315] = &subbrute_protocol_chamberlain_9bit_315,
  389. [SubBruteAttackChamberlain9bit390] = &subbrute_protocol_chamberlain_9bit_390,
  390. [SubBruteAttackChamberlain9bit433] = &subbrute_protocol_chamberlain_9bit_433,
  391. [SubBruteAttackChamberlain8bit300] = &subbrute_protocol_chamberlain_8bit_300,
  392. [SubBruteAttackChamberlain8bit315] = &subbrute_protocol_chamberlain_8bit_315,
  393. [SubBruteAttackChamberlain8bit390] = &subbrute_protocol_chamberlain_8bit_390,
  394. [SubBruteAttackChamberlain7bit300] = &subbrute_protocol_chamberlain_7bit_300,
  395. [SubBruteAttackChamberlain7bit315] = &subbrute_protocol_chamberlain_7bit_315,
  396. [SubBruteAttackChamberlain7bit390] = &subbrute_protocol_chamberlain_7bit_390,
  397. [SubBruteAttackLinear10bit300] = &subbrute_protocol_linear_10bit_300,
  398. [SubBruteAttackLinear10bit310] = &subbrute_protocol_linear_10bit_310,
  399. [SubBruteAttackLinearDelta8bit310] = &subbrute_protocol_linear_delta_8bit_310,
  400. [SubBruteAttackUNILARM24bit330] = &subbrute_protocol_unilarm_24bit_330,
  401. [SubBruteAttackUNILARM24bit433] = &subbrute_protocol_unilarm_24bit_433,
  402. [SubBruteAttackSMC532624bit330] = &subbrute_protocol_smc5326_24bit_330,
  403. [SubBruteAttackSMC532624bit433] = &subbrute_protocol_smc5326_24bit_433,
  404. [SubBruteAttackPT226024bit315] = &subbrute_protocol_pt2260_24bit_315,
  405. [SubBruteAttackPT226024bit330] = &subbrute_protocol_pt2260_24bit_330,
  406. [SubBruteAttackPT226024bit390] = &subbrute_protocol_pt2260_24bit_390,
  407. [SubBruteAttackPT226024bit433] = &subbrute_protocol_pt2260_24bit_433,
  408. [SubBruteAttackLoadFile] = &subbrute_protocol_load_file};
  409. static const char* subbrute_protocol_file_types[] = {
  410. [CAMEFileProtocol] = "CAME",
  411. [NICEFileProtocol] = "Nice FLO",
  412. [ChamberlainFileProtocol] = "Cham_Code",
  413. [LinearFileProtocol] = "Linear",
  414. [LinearDeltaFileProtocol] = "LinearDelta3",
  415. [PrincetonFileProtocol] = "Princeton",
  416. [RAWFileProtocol] = "RAW",
  417. [BETTFileProtocol] = "BETT",
  418. [ClemsaFileProtocol] = "Clemsa",
  419. [DoitrandFileProtocol] = "Doitrand",
  420. [GateTXFileProtocol] = "GateTX",
  421. [MagellanFileProtocol] = "Magellan",
  422. [IntertechnoV3FileProtocol] = "Intertechno_V3",
  423. [AnsonicFileProtocol] = "Ansonic",
  424. [SMC5326FileProtocol] = "SMC5326",
  425. [UNILARMFileProtocol] = "SMC5326",
  426. [PT2260FileProtocol] = "Princeton",
  427. [HoneywellFileProtocol] = "Honeywell",
  428. [HoltekFileProtocol] = "Holtek_HT12X",
  429. [UnknownFileProtocol] = "Unknown"};
  430. /**
  431. * Values to not use less memory for packet parse operations
  432. */
  433. static const char* subbrute_key_file_start_no_tail =
  434. "Filetype: Flipper SubGhz Key File\nVersion: 1\nFrequency: %u\nPreset: %s\nProtocol: %s\nBit: %d\nKey: %s\nRepeat: %d\n";
  435. static const char* subbrute_key_file_start_with_tail =
  436. "Filetype: Flipper SubGhz Key File\nVersion: 1\nFrequency: %u\nPreset: %s\nProtocol: %s\nBit: %d\nKey: %s\nTE: %d\nRepeat: %d\n";
  437. static const char* subbrute_key_small_no_tail = "Bit: %d\nKey: %s\nRepeat: %d\n";
  438. //static const char* subbrute_key_small_raw =
  439. // "Filetype: Flipper SubGhz Key File\nVersion: 1\nFrequency: %u\nPreset: %s\nProtocol: %s\nBit: %d\n";
  440. static const char* subbrute_key_small_with_tail = "Bit: %d\nKey: %s\nTE: %d\nRepeat: %d\n";
  441. const char* subbrute_protocol_name(SubBruteAttacks index) {
  442. return subbrute_protocol_names[index];
  443. }
  444. const SubBruteProtocol* subbrute_protocol(SubBruteAttacks index) {
  445. return subbrute_protocol_registry[index];
  446. }
  447. uint8_t subbrute_protocol_repeats_count(SubBruteAttacks index) {
  448. return subbrute_protocol_registry[index]->repeat;
  449. }
  450. const char* subbrute_protocol_preset(FuriHalSubGhzPreset preset) {
  451. return subbrute_protocol_presets[preset];
  452. }
  453. const char* subbrute_protocol_file(SubBruteFileProtocol protocol) {
  454. return subbrute_protocol_file_types[protocol];
  455. }
  456. FuriHalSubGhzPreset subbrute_protocol_convert_preset(FuriString* preset_name) {
  457. for(size_t i = FuriHalSubGhzPresetIDLE; i < FuriHalSubGhzPresetCustom; i++) {
  458. if(furi_string_cmp_str(preset_name, subbrute_protocol_presets[i]) == 0) {
  459. return i;
  460. }
  461. }
  462. return FuriHalSubGhzPresetIDLE;
  463. }
  464. SubBruteFileProtocol subbrute_protocol_file_protocol_name(FuriString* name) {
  465. for(size_t i = CAMEFileProtocol; i < TotalFileProtocol - 1; i++) {
  466. if(furi_string_cmp_str(name, subbrute_protocol_file_types[i]) == 0) {
  467. return i;
  468. }
  469. }
  470. return UnknownFileProtocol;
  471. }
  472. void subbrute_protocol_create_candidate_for_existing_file(
  473. FuriString* candidate,
  474. uint64_t step,
  475. uint8_t bit_index,
  476. uint64_t file_key,
  477. bool two_bytes) {
  478. uint8_t p[8];
  479. for(int i = 0; i < 8; i++) {
  480. p[i] = (uint8_t)(file_key >> 8 * (7 - i)) & 0xFF;
  481. }
  482. uint8_t low_byte = step & (0xff);
  483. uint8_t high_byte = (step >> 8) & 0xff;
  484. size_t size = sizeof(uint64_t);
  485. for(uint8_t i = 0; i < size; i++) {
  486. if(i == bit_index - 1 && two_bytes) {
  487. furi_string_cat_printf(candidate, "%02X %02X", high_byte, low_byte);
  488. i++;
  489. } else if(i == bit_index) {
  490. furi_string_cat_printf(candidate, "%02X", low_byte);
  491. } else if(p[i] != 0) {
  492. furi_string_cat_printf(candidate, "%02X", p[i]);
  493. } else {
  494. furi_string_cat_printf(candidate, "%s", "00");
  495. }
  496. if(i < size - 1) {
  497. furi_string_push_back(candidate, ' ');
  498. }
  499. }
  500. #ifdef FURI_DEBUG
  501. FURI_LOG_D(TAG, "file candidate: %s, step: %lld", furi_string_get_cstr(candidate), step);
  502. #endif
  503. }
  504. void subbrute_protocol_create_candidate_for_default(
  505. FuriString* candidate,
  506. SubBruteFileProtocol file,
  507. uint64_t step) {
  508. uint8_t p[8];
  509. if(file == SMC5326FileProtocol) {
  510. const uint8_t lut[] = {0x00, 0x02, 0x03}; // 00, 10, 11
  511. const uint64_t gate1 = 0x01D5; // 111010101
  512. //const uint8_t gate2 = 0x0175; // 101110101
  513. uint64_t total = 0;
  514. for(size_t j = 0; j < 8; j++) {
  515. total |= lut[step % 3] << (2 * j);
  516. double sub_step = step / 3;
  517. step = (uint64_t)floor(sub_step);
  518. }
  519. total <<= 9;
  520. total |= gate1;
  521. for(int i = 0; i < 8; i++) {
  522. p[i] = (uint8_t)(total >> 8 * (7 - i)) & 0xFF;
  523. }
  524. } else if(file == UNILARMFileProtocol) {
  525. const uint8_t lut[] = {0x00, 0x02, 0x03}; // 00, 10, 11
  526. const uint64_t gate1 = 3 << 7;
  527. //const uint8_t gate2 = 3 << 5;
  528. uint64_t total = 0;
  529. for(size_t j = 0; j < 8; j++) {
  530. total |= lut[step % 3] << (2 * j);
  531. double sub_step = step / 3;
  532. step = (uint64_t)floor(sub_step);
  533. }
  534. total <<= 9;
  535. total |= gate1;
  536. for(int i = 0; i < 8; i++) {
  537. p[i] = (uint8_t)(total >> 8 * (7 - i)) & 0xFF;
  538. }
  539. } else if(file == PT2260FileProtocol) {
  540. const uint8_t lut[] = {0x00, 0x01, 0x03}; // 00, 01, 11
  541. const uint64_t button_open = 0x03; // 11
  542. //const uint8_t button_lock = 0x0C; // 1100
  543. //const uint8_t button_stop = 0x30; // 110000
  544. //const uint8_t button_close = 0xC0; // 11000000
  545. uint64_t total = 0;
  546. for(size_t j = 0; j < 8; j++) {
  547. total |= lut[step % 3] << (2 * j);
  548. double sub_step = step / 3;
  549. step = (uint64_t)floor(sub_step);
  550. }
  551. total <<= 8;
  552. total |= button_open;
  553. for(int i = 0; i < 8; i++) {
  554. p[i] = (uint8_t)(total >> 8 * (7 - i)) & 0xFF;
  555. }
  556. } else {
  557. for(int i = 0; i < 8; i++) {
  558. p[i] = (uint8_t)(step >> 8 * (7 - i)) & 0xFF;
  559. }
  560. }
  561. size_t size = sizeof(uint64_t);
  562. for(uint8_t i = 0; i < size; i++) {
  563. if(p[i] != 0) {
  564. furi_string_cat_printf(candidate, "%02X", p[i]);
  565. } else {
  566. furi_string_cat_printf(candidate, "%s", "00");
  567. }
  568. if(i < size - 1) {
  569. furi_string_push_back(candidate, ' ');
  570. }
  571. }
  572. #ifdef FURI_DEBUG
  573. FURI_LOG_D(TAG, "candidate: %s, step: %lld", furi_string_get_cstr(candidate), step);
  574. #endif
  575. }
  576. void subbrute_protocol_default_payload(
  577. Stream* stream,
  578. SubBruteFileProtocol file,
  579. uint64_t step,
  580. uint8_t bits,
  581. uint32_t te,
  582. uint8_t repeat) {
  583. FuriString* candidate = furi_string_alloc();
  584. subbrute_protocol_create_candidate_for_default(candidate, file, step);
  585. #ifdef FURI_DEBUG
  586. FURI_LOG_D(
  587. TAG,
  588. "candidate: %s, step: %lld, repeat: %d, te: %s",
  589. furi_string_get_cstr(candidate),
  590. step,
  591. repeat,
  592. te ? "true" : "false");
  593. #endif
  594. stream_clean(stream);
  595. if(te) {
  596. stream_write_format(
  597. stream,
  598. subbrute_key_small_with_tail,
  599. bits,
  600. furi_string_get_cstr(candidate),
  601. te,
  602. repeat);
  603. } else {
  604. stream_write_format(
  605. stream, subbrute_key_small_no_tail, bits, furi_string_get_cstr(candidate), repeat);
  606. }
  607. furi_string_free(candidate);
  608. }
  609. void subbrute_protocol_file_payload(
  610. Stream* stream,
  611. uint64_t step,
  612. uint8_t bits,
  613. uint32_t te,
  614. uint8_t repeat,
  615. uint8_t bit_index,
  616. uint64_t file_key,
  617. bool two_bytes) {
  618. FuriString* candidate = furi_string_alloc();
  619. subbrute_protocol_create_candidate_for_existing_file(
  620. candidate, step, bit_index, file_key, two_bytes);
  621. #ifdef FURI_DEBUG
  622. FURI_LOG_D(
  623. TAG,
  624. "candidate: %s, step: %lld, repeat: %d, te: %s",
  625. furi_string_get_cstr(candidate),
  626. step,
  627. repeat,
  628. te ? "true" : "false");
  629. #endif
  630. stream_clean(stream);
  631. if(te) {
  632. stream_write_format(
  633. stream,
  634. subbrute_key_small_with_tail,
  635. bits,
  636. furi_string_get_cstr(candidate),
  637. te,
  638. repeat);
  639. } else {
  640. stream_write_format(
  641. stream, subbrute_key_small_no_tail, bits, furi_string_get_cstr(candidate), repeat);
  642. }
  643. furi_string_free(candidate);
  644. }
  645. void subbrute_protocol_default_generate_file(
  646. Stream* stream,
  647. uint32_t frequency,
  648. FuriHalSubGhzPreset preset,
  649. SubBruteFileProtocol file,
  650. uint64_t step,
  651. uint8_t bits,
  652. uint32_t te,
  653. uint8_t repeat) {
  654. FuriString* candidate = furi_string_alloc();
  655. subbrute_protocol_create_candidate_for_default(candidate, file, step);
  656. #ifdef FURI_DEBUG
  657. FURI_LOG_D(TAG, "candidate: %s, step: %lld", furi_string_get_cstr(candidate), step);
  658. #endif
  659. stream_clean(stream);
  660. if(te) {
  661. stream_write_format(
  662. stream,
  663. subbrute_key_file_start_with_tail,
  664. frequency,
  665. subbrute_protocol_preset(preset),
  666. subbrute_protocol_file(file),
  667. bits,
  668. furi_string_get_cstr(candidate),
  669. te,
  670. repeat);
  671. } else {
  672. stream_write_format(
  673. stream,
  674. subbrute_key_file_start_no_tail,
  675. frequency,
  676. subbrute_protocol_preset(preset),
  677. subbrute_protocol_file(file),
  678. bits,
  679. furi_string_get_cstr(candidate),
  680. repeat);
  681. }
  682. furi_string_free(candidate);
  683. }
  684. void subbrute_protocol_file_generate_file(
  685. Stream* stream,
  686. uint32_t frequency,
  687. FuriHalSubGhzPreset preset,
  688. SubBruteFileProtocol file,
  689. uint64_t step,
  690. uint8_t bits,
  691. uint32_t te,
  692. uint8_t repeat,
  693. uint8_t bit_index,
  694. uint64_t file_key,
  695. bool two_bytes) {
  696. FuriString* candidate = furi_string_alloc();
  697. // char subbrute_payload_byte[8];
  698. //furi_string_set_str(candidate, file_key);
  699. subbrute_protocol_create_candidate_for_existing_file(
  700. candidate, step, bit_index, file_key, two_bytes);
  701. stream_clean(stream);
  702. if(te) {
  703. stream_write_format(
  704. stream,
  705. subbrute_key_file_start_with_tail,
  706. frequency,
  707. subbrute_protocol_preset(preset),
  708. subbrute_protocol_file(file),
  709. bits,
  710. furi_string_get_cstr(candidate),
  711. te,
  712. repeat);
  713. } else {
  714. stream_write_format(
  715. stream,
  716. subbrute_key_file_start_no_tail,
  717. frequency,
  718. subbrute_protocol_preset(preset),
  719. subbrute_protocol_file(file),
  720. bits,
  721. furi_string_get_cstr(candidate),
  722. repeat);
  723. }
  724. furi_string_free(candidate);
  725. }
  726. uint64_t
  727. subbrute_protocol_calc_max_value(SubBruteAttacks attack_type, uint8_t bits, bool two_bytes) {
  728. uint64_t max_value;
  729. if(attack_type == SubBruteAttackLoadFile) {
  730. max_value = two_bytes ? 0xFFFF : 0xFF;
  731. } else if(
  732. attack_type == SubBruteAttackSMC532624bit330 ||
  733. attack_type == SubBruteAttackSMC532624bit433 ||
  734. attack_type == SubBruteAttackUNILARM24bit330 ||
  735. attack_type == SubBruteAttackUNILARM24bit433 ||
  736. attack_type == SubBruteAttackPT226024bit315 ||
  737. attack_type == SubBruteAttackPT226024bit330 ||
  738. attack_type == SubBruteAttackPT226024bit390 ||
  739. attack_type == SubBruteAttackPT226024bit433) {
  740. max_value = 6561;
  741. } else {
  742. FuriString* max_value_s;
  743. max_value_s = furi_string_alloc();
  744. for(uint8_t i = 0; i < bits; i++) {
  745. furi_string_cat_printf(max_value_s, "1");
  746. }
  747. max_value = (uint64_t)strtol(furi_string_get_cstr(max_value_s), NULL, 2);
  748. furi_string_free(max_value_s);
  749. }
  750. return max_value;
  751. }