subbrute_protocols.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815
  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. * UNILARM 24bit 330MHz
  227. */
  228. const SubBruteProtocol subbrute_protocol_unilarm_24bit_330 = {
  229. .frequency = 330000000,
  230. .bits = 25,
  231. .te = 209,
  232. .repeat = 5,
  233. .preset = FuriHalSubGhzPresetOok650Async,
  234. .file = UNILARMFileProtocol};
  235. /**
  236. * UNILARM 24bit 433MHz
  237. */
  238. const SubBruteProtocol subbrute_protocol_unilarm_24bit_433 = {
  239. .frequency = 433920000,
  240. .bits = 25,
  241. .te = 209,
  242. .repeat = 5,
  243. .preset = FuriHalSubGhzPresetOok650Async,
  244. .file = UNILARMFileProtocol};
  245. /**
  246. * SMC5326 24bit 330MHz
  247. */
  248. const SubBruteProtocol subbrute_protocol_smc5326_24bit_330 = {
  249. .frequency = 330000000,
  250. .bits = 25,
  251. .te = 320,
  252. .repeat = 5,
  253. .preset = FuriHalSubGhzPresetOok650Async,
  254. .file = SMC5326FileProtocol};
  255. /**
  256. * SMC5326 24bit 433MHz
  257. */
  258. const SubBruteProtocol subbrute_protocol_smc5326_24bit_433 = {
  259. .frequency = 433920000,
  260. .bits = 25,
  261. .te = 320,
  262. .repeat = 5,
  263. .preset = FuriHalSubGhzPresetOok650Async,
  264. .file = SMC5326FileProtocol};
  265. /**
  266. * PT2260 (Princeton) 24bit 315MHz
  267. */
  268. const SubBruteProtocol subbrute_protocol_pt2260_24bit_315 = {
  269. .frequency = 315000000,
  270. .bits = 24,
  271. .te = 286,
  272. .repeat = 5,
  273. .preset = FuriHalSubGhzPresetOok650Async,
  274. .file = PT2260FileProtocol};
  275. /**
  276. * PT2260 (Princeton) 24bit 330MHz
  277. */
  278. const SubBruteProtocol subbrute_protocol_pt2260_24bit_330 = {
  279. .frequency = 330000000,
  280. .bits = 24,
  281. .te = 286,
  282. .repeat = 5,
  283. .preset = FuriHalSubGhzPresetOok650Async,
  284. .file = PT2260FileProtocol};
  285. /**
  286. * PT2260 (Princeton) 24bit 390MHz
  287. */
  288. const SubBruteProtocol subbrute_protocol_pt2260_24bit_390 = {
  289. .frequency = 390000000,
  290. .bits = 24,
  291. .te = 286,
  292. .repeat = 5,
  293. .preset = FuriHalSubGhzPresetOok650Async,
  294. .file = PT2260FileProtocol};
  295. /**
  296. * PT2260 (Princeton) 24bit 433MHz
  297. */
  298. const SubBruteProtocol subbrute_protocol_pt2260_24bit_433 = {
  299. .frequency = 433920000,
  300. .bits = 24,
  301. .te = 286,
  302. .repeat = 5,
  303. .preset = FuriHalSubGhzPresetOok650Async,
  304. .file = PT2260FileProtocol};
  305. /**
  306. * Holtek FM 12bit 433MHz
  307. */
  308. const SubBruteProtocol subbrute_protocol_holtek_12bit_433 = {
  309. .frequency = 433920000,
  310. .bits = 12,
  311. .te = 204,
  312. .repeat = 4,
  313. .preset = FuriHalSubGhzPreset2FSKDev476Async,
  314. .file = HoltekFileProtocol};
  315. /**
  316. * BF existing dump
  317. */
  318. const SubBruteProtocol subbrute_protocol_load_file =
  319. {0, 0, 0, 3, FuriHalSubGhzPresetOok650Async, UnknownFileProtocol};
  320. static const char* subbrute_protocol_names[] = {
  321. [SubBruteAttackCAME12bit303] = "CAME 12bit 303MHz",
  322. [SubBruteAttackCAME12bit307] = "CAME 12bit 307MHz",
  323. [SubBruteAttackCAME12bit315] = "CAME 12bit 315MHz",
  324. [SubBruteAttackCAME12bit433] = "CAME 12bit 433MHz",
  325. [SubBruteAttackCAME12bit868] = "CAME 12bit 868MHz",
  326. [SubBruteAttackNICE12bit433] = "NICE 12bit 433MHz",
  327. [SubBruteAttackNICE12bit868] = "NICE 12bit 868MHz",
  328. [SubBruteAttackAnsonic12bit433075] = "Ansonic 12bit 433.07MHz",
  329. [SubBruteAttackAnsonic12bit433] = "Ansonic 12bit 433.92MHz",
  330. [SubBruteAttackAnsonic12bit434] = "Ansonic 12bit 434.07MHz",
  331. [SubBruteAttackHoltek12bit433] = "Holtek FM 12bit 433MHz",
  332. [SubBruteAttackChamberlain9bit300] = "Chamberlain 9bit 300MHz",
  333. [SubBruteAttackChamberlain9bit315] = "Chamberlain 9bit 315MHz",
  334. [SubBruteAttackChamberlain9bit390] = "Chamberlain 9bit 390MHz",
  335. [SubBruteAttackChamberlain9bit433] = "Chamberlain 9bit 433MHz",
  336. [SubBruteAttackChamberlain8bit300] = "Chamberlain 8bit 300MHz",
  337. [SubBruteAttackChamberlain8bit315] = "Chamberlain 8bit 315MHz",
  338. [SubBruteAttackChamberlain8bit390] = "Chamberlain 8bit 390MHz",
  339. [SubBruteAttackChamberlain7bit300] = "Chamberlain 7bit 300MHz",
  340. [SubBruteAttackChamberlain7bit315] = "Chamberlain 7bit 315MHz",
  341. [SubBruteAttackChamberlain7bit390] = "Chamberlain 7bit 390MHz",
  342. [SubBruteAttackLinear10bit300] = "Linear 10bit 300MHz",
  343. [SubBruteAttackLinear10bit310] = "Linear 10bit 310MHz",
  344. [SubBruteAttackUNILARM24bit330] = "UNILARM 25bit 330MHz",
  345. [SubBruteAttackUNILARM24bit433] = "UNILARM 25bit 433MHz",
  346. [SubBruteAttackSMC532624bit330] = "SMC5326 25bit 330MHz",
  347. [SubBruteAttackSMC532624bit433] = "SMC5326 25bit 433MHz",
  348. [SubBruteAttackPT226024bit315] = "PT2260 24bit 315MHz",
  349. [SubBruteAttackPT226024bit330] = "PT2260 24bit 330MHz",
  350. [SubBruteAttackPT226024bit390] = "PT2260 24bit 390MHz",
  351. [SubBruteAttackPT226024bit433] = "PT2260 24bit 433MHz",
  352. [SubBruteAttackLoadFile] = "BF existing dump",
  353. [SubBruteAttackTotalCount] = "Total Count",
  354. };
  355. static const char* subbrute_protocol_presets[] = {
  356. [FuriHalSubGhzPresetIDLE] = "FuriHalSubGhzPresetIDLE",
  357. [FuriHalSubGhzPresetOok270Async] = "FuriHalSubGhzPresetOok270Async",
  358. [FuriHalSubGhzPresetOok650Async] = "FuriHalSubGhzPresetOok650Async",
  359. [FuriHalSubGhzPreset2FSKDev238Async] = "FuriHalSubGhzPreset2FSKDev238Async",
  360. [FuriHalSubGhzPreset2FSKDev476Async] = "FuriHalSubGhzPreset2FSKDev476Async",
  361. [FuriHalSubGhzPresetMSK99_97KbAsync] = "FuriHalSubGhzPresetMSK99_97KbAsync",
  362. [FuriHalSubGhzPresetGFSK9_99KbAsync] = "FuriHalSubGhzPresetGFSK9_99KbAsync",
  363. };
  364. const SubBruteProtocol* subbrute_protocol_registry[] = {
  365. [SubBruteAttackCAME12bit303] = &subbrute_protocol_came_12bit_303,
  366. [SubBruteAttackCAME12bit307] = &subbrute_protocol_came_12bit_307,
  367. [SubBruteAttackCAME12bit315] = &subbrute_protocol_came_12bit_315,
  368. [SubBruteAttackCAME12bit433] = &subbrute_protocol_came_12bit_433,
  369. [SubBruteAttackCAME12bit868] = &subbrute_protocol_came_12bit_868,
  370. [SubBruteAttackNICE12bit433] = &subbrute_protocol_nice_12bit_433,
  371. [SubBruteAttackNICE12bit868] = &subbrute_protocol_nice_12bit_868,
  372. [SubBruteAttackAnsonic12bit433075] = &subbrute_protocol_ansonic_12bit_433075,
  373. [SubBruteAttackAnsonic12bit433] = &subbrute_protocol_ansonic_12bit_433,
  374. [SubBruteAttackAnsonic12bit434] = &subbrute_protocol_ansonic_12bit_434,
  375. [SubBruteAttackHoltek12bit433] = &subbrute_protocol_holtek_12bit_433,
  376. [SubBruteAttackChamberlain9bit300] = &subbrute_protocol_chamberlain_9bit_300,
  377. [SubBruteAttackChamberlain9bit315] = &subbrute_protocol_chamberlain_9bit_315,
  378. [SubBruteAttackChamberlain9bit390] = &subbrute_protocol_chamberlain_9bit_390,
  379. [SubBruteAttackChamberlain9bit433] = &subbrute_protocol_chamberlain_9bit_433,
  380. [SubBruteAttackChamberlain8bit300] = &subbrute_protocol_chamberlain_8bit_300,
  381. [SubBruteAttackChamberlain8bit315] = &subbrute_protocol_chamberlain_8bit_315,
  382. [SubBruteAttackChamberlain8bit390] = &subbrute_protocol_chamberlain_8bit_390,
  383. [SubBruteAttackChamberlain7bit300] = &subbrute_protocol_chamberlain_7bit_300,
  384. [SubBruteAttackChamberlain7bit315] = &subbrute_protocol_chamberlain_7bit_315,
  385. [SubBruteAttackChamberlain7bit390] = &subbrute_protocol_chamberlain_7bit_390,
  386. [SubBruteAttackLinear10bit300] = &subbrute_protocol_linear_10bit_300,
  387. [SubBruteAttackLinear10bit310] = &subbrute_protocol_linear_10bit_310,
  388. [SubBruteAttackUNILARM24bit330] = &subbrute_protocol_unilarm_24bit_330,
  389. [SubBruteAttackUNILARM24bit433] = &subbrute_protocol_unilarm_24bit_433,
  390. [SubBruteAttackSMC532624bit330] = &subbrute_protocol_smc5326_24bit_330,
  391. [SubBruteAttackSMC532624bit433] = &subbrute_protocol_smc5326_24bit_433,
  392. [SubBruteAttackPT226024bit315] = &subbrute_protocol_pt2260_24bit_315,
  393. [SubBruteAttackPT226024bit330] = &subbrute_protocol_pt2260_24bit_330,
  394. [SubBruteAttackPT226024bit390] = &subbrute_protocol_pt2260_24bit_390,
  395. [SubBruteAttackPT226024bit433] = &subbrute_protocol_pt2260_24bit_433,
  396. [SubBruteAttackLoadFile] = &subbrute_protocol_load_file};
  397. static const char* subbrute_protocol_file_types[] = {
  398. [CAMEFileProtocol] = "CAME",
  399. [NICEFileProtocol] = "Nice FLO",
  400. [ChamberlainFileProtocol] = "Cham_Code",
  401. [LinearFileProtocol] = "Linear",
  402. [PrincetonFileProtocol] = "Princeton",
  403. [RAWFileProtocol] = "RAW",
  404. [BETTFileProtocol] = "BETT",
  405. [ClemsaFileProtocol] = "Clemsa",
  406. [DoitrandFileProtocol] = "Doitrand",
  407. [GateTXFileProtocol] = "GateTX",
  408. [MagellanFileProtocol] = "Magellan",
  409. [IntertechnoV3FileProtocol] = "Intertechno_V3",
  410. [AnsonicFileProtocol] = "Ansonic",
  411. [SMC5326FileProtocol] = "SMC5326",
  412. [UNILARMFileProtocol] = "SMC5326",
  413. [PT2260FileProtocol] = "Princeton",
  414. [HoneywellFileProtocol] = "Honeywell",
  415. [HoltekFileProtocol] = "Holtek_HT12X",
  416. [UnknownFileProtocol] = "Unknown"};
  417. /**
  418. * Values to not use less memory for packet parse operations
  419. */
  420. static const char* subbrute_key_file_start_no_tail =
  421. "Filetype: Flipper SubGhz Key File\nVersion: 1\nFrequency: %u\nPreset: %s\nProtocol: %s\nBit: %d\nKey: %s\nRepeat: %d\n";
  422. static const char* subbrute_key_file_start_with_tail =
  423. "Filetype: Flipper SubGhz Key File\nVersion: 1\nFrequency: %u\nPreset: %s\nProtocol: %s\nBit: %d\nKey: %s\nTE: %d\nRepeat: %d\n";
  424. static const char* subbrute_key_small_no_tail = "Bit: %d\nKey: %s\nRepeat: %d\n";
  425. //static const char* subbrute_key_small_raw =
  426. // "Filetype: Flipper SubGhz Key File\nVersion: 1\nFrequency: %u\nPreset: %s\nProtocol: %s\nBit: %d\n";
  427. static const char* subbrute_key_small_with_tail = "Bit: %d\nKey: %s\nTE: %d\nRepeat: %d\n";
  428. const char* subbrute_protocol_name(SubBruteAttacks index) {
  429. return subbrute_protocol_names[index];
  430. }
  431. const SubBruteProtocol* subbrute_protocol(SubBruteAttacks index) {
  432. return subbrute_protocol_registry[index];
  433. }
  434. uint8_t subbrute_protocol_repeats_count(SubBruteAttacks index) {
  435. return subbrute_protocol_registry[index]->repeat;
  436. }
  437. const char* subbrute_protocol_preset(FuriHalSubGhzPreset preset) {
  438. return subbrute_protocol_presets[preset];
  439. }
  440. const char* subbrute_protocol_file(SubBruteFileProtocol protocol) {
  441. return subbrute_protocol_file_types[protocol];
  442. }
  443. FuriHalSubGhzPreset subbrute_protocol_convert_preset(FuriString* preset_name) {
  444. for(size_t i = FuriHalSubGhzPresetIDLE; i < FuriHalSubGhzPresetCustom; i++) {
  445. if(furi_string_cmp_str(preset_name, subbrute_protocol_presets[i]) == 0) {
  446. return i;
  447. }
  448. }
  449. return FuriHalSubGhzPresetIDLE;
  450. }
  451. SubBruteFileProtocol subbrute_protocol_file_protocol_name(FuriString* name) {
  452. for(size_t i = CAMEFileProtocol; i < TotalFileProtocol - 1; i++) {
  453. if(furi_string_cmp_str(name, subbrute_protocol_file_types[i]) == 0) {
  454. return i;
  455. }
  456. }
  457. return UnknownFileProtocol;
  458. }
  459. void subbrute_protocol_create_candidate_for_existing_file(
  460. FuriString* candidate,
  461. uint64_t step,
  462. uint8_t bit_index,
  463. uint64_t file_key,
  464. bool two_bytes) {
  465. uint8_t p[8];
  466. for(int i = 0; i < 8; i++) {
  467. p[i] = (uint8_t)(file_key >> 8 * (7 - i)) & 0xFF;
  468. }
  469. uint8_t low_byte = step & (0xff);
  470. uint8_t high_byte = (step >> 8) & 0xff;
  471. size_t size = sizeof(uint64_t);
  472. for(uint8_t i = 0; i < size; i++) {
  473. if(i == bit_index - 1 && two_bytes) {
  474. furi_string_cat_printf(candidate, "%02X %02X", high_byte, low_byte);
  475. i++;
  476. } else if(i == bit_index) {
  477. furi_string_cat_printf(candidate, "%02X", low_byte);
  478. } else if(p[i] != 0) {
  479. furi_string_cat_printf(candidate, "%02X", p[i]);
  480. } else {
  481. furi_string_cat_printf(candidate, "%s", "00");
  482. }
  483. if(i < size - 1) {
  484. furi_string_push_back(candidate, ' ');
  485. }
  486. }
  487. #ifdef FURI_DEBUG
  488. FURI_LOG_D(TAG, "file candidate: %s, step: %lld", furi_string_get_cstr(candidate), step);
  489. #endif
  490. }
  491. void subbrute_protocol_create_candidate_for_default(
  492. FuriString* candidate,
  493. SubBruteFileProtocol file,
  494. uint64_t step) {
  495. uint8_t p[8];
  496. if(file == SMC5326FileProtocol) {
  497. const uint8_t lut[] = {0x00, 0x02, 0x03}; // 00, 10, 11
  498. const uint64_t gate1 = 0x01D5; // 111010101
  499. //const uint8_t gate2 = 0x0175; // 101110101
  500. uint64_t total = 0;
  501. for(size_t j = 0; j < 8; j++) {
  502. total |= lut[step % 3] << (2 * j);
  503. double sub_step = step / 3;
  504. step = (uint64_t)floor(sub_step);
  505. }
  506. total <<= 9;
  507. total |= gate1;
  508. for(int i = 0; i < 8; i++) {
  509. p[i] = (uint8_t)(total >> 8 * (7 - i)) & 0xFF;
  510. }
  511. } else if(file == UNILARMFileProtocol) {
  512. const uint8_t lut[] = {0x00, 0x02, 0x03}; // 00, 10, 11
  513. const uint64_t gate1 = 3 << 7;
  514. //const uint8_t gate2 = 3 << 5;
  515. uint64_t total = 0;
  516. for(size_t j = 0; j < 8; j++) {
  517. total |= lut[step % 3] << (2 * j);
  518. double sub_step = step / 3;
  519. step = (uint64_t)floor(sub_step);
  520. }
  521. total <<= 9;
  522. total |= gate1;
  523. for(int i = 0; i < 8; i++) {
  524. p[i] = (uint8_t)(total >> 8 * (7 - i)) & 0xFF;
  525. }
  526. } else if(file == PT2260FileProtocol) {
  527. const uint8_t lut[] = {0x00, 0x01, 0x03}; // 00, 01, 11
  528. const uint64_t button_open = 0x03; // 11
  529. //const uint8_t button_lock = 0x0C; // 1100
  530. //const uint8_t button_stop = 0x30; // 110000
  531. //const uint8_t button_close = 0xC0; // 11000000
  532. uint64_t total = 0;
  533. for(size_t j = 0; j < 8; j++) {
  534. total |= lut[step % 3] << (2 * j);
  535. double sub_step = step / 3;
  536. step = (uint64_t)floor(sub_step);
  537. }
  538. total <<= 8;
  539. total |= button_open;
  540. for(int i = 0; i < 8; i++) {
  541. p[i] = (uint8_t)(total >> 8 * (7 - i)) & 0xFF;
  542. }
  543. } else {
  544. for(int i = 0; i < 8; i++) {
  545. p[i] = (uint8_t)(step >> 8 * (7 - i)) & 0xFF;
  546. }
  547. }
  548. size_t size = sizeof(uint64_t);
  549. for(uint8_t i = 0; i < size; i++) {
  550. if(p[i] != 0) {
  551. furi_string_cat_printf(candidate, "%02X", p[i]);
  552. } else {
  553. furi_string_cat_printf(candidate, "%s", "00");
  554. }
  555. if(i < size - 1) {
  556. furi_string_push_back(candidate, ' ');
  557. }
  558. }
  559. #ifdef FURI_DEBUG
  560. FURI_LOG_D(TAG, "candidate: %s, step: %lld", furi_string_get_cstr(candidate), step);
  561. #endif
  562. }
  563. void subbrute_protocol_default_payload(
  564. Stream* stream,
  565. SubBruteFileProtocol file,
  566. uint64_t step,
  567. uint8_t bits,
  568. uint32_t te,
  569. uint8_t repeat) {
  570. FuriString* candidate = furi_string_alloc();
  571. subbrute_protocol_create_candidate_for_default(candidate, file, step);
  572. #ifdef FURI_DEBUG
  573. FURI_LOG_D(
  574. TAG,
  575. "candidate: %s, step: %lld, repeat: %d, te: %s",
  576. furi_string_get_cstr(candidate),
  577. step,
  578. repeat,
  579. te ? "true" : "false");
  580. #endif
  581. stream_clean(stream);
  582. if(te) {
  583. stream_write_format(
  584. stream,
  585. subbrute_key_small_with_tail,
  586. bits,
  587. furi_string_get_cstr(candidate),
  588. te,
  589. repeat);
  590. } else {
  591. stream_write_format(
  592. stream, subbrute_key_small_no_tail, bits, furi_string_get_cstr(candidate), repeat);
  593. }
  594. furi_string_free(candidate);
  595. }
  596. void subbrute_protocol_file_payload(
  597. Stream* stream,
  598. uint64_t step,
  599. uint8_t bits,
  600. uint32_t te,
  601. uint8_t repeat,
  602. uint8_t bit_index,
  603. uint64_t file_key,
  604. bool two_bytes) {
  605. FuriString* candidate = furi_string_alloc();
  606. subbrute_protocol_create_candidate_for_existing_file(
  607. candidate, step, bit_index, file_key, two_bytes);
  608. #ifdef FURI_DEBUG
  609. FURI_LOG_D(
  610. TAG,
  611. "candidate: %s, step: %lld, repeat: %d, te: %s",
  612. furi_string_get_cstr(candidate),
  613. step,
  614. repeat,
  615. te ? "true" : "false");
  616. #endif
  617. stream_clean(stream);
  618. if(te) {
  619. stream_write_format(
  620. stream,
  621. subbrute_key_small_with_tail,
  622. bits,
  623. furi_string_get_cstr(candidate),
  624. te,
  625. repeat);
  626. } else {
  627. stream_write_format(
  628. stream, subbrute_key_small_no_tail, bits, furi_string_get_cstr(candidate), repeat);
  629. }
  630. furi_string_free(candidate);
  631. }
  632. void subbrute_protocol_default_generate_file(
  633. Stream* stream,
  634. uint32_t frequency,
  635. FuriHalSubGhzPreset preset,
  636. SubBruteFileProtocol file,
  637. uint64_t step,
  638. uint8_t bits,
  639. uint32_t te,
  640. uint8_t repeat) {
  641. FuriString* candidate = furi_string_alloc();
  642. subbrute_protocol_create_candidate_for_default(candidate, file, step);
  643. #ifdef FURI_DEBUG
  644. FURI_LOG_D(TAG, "candidate: %s, step: %lld", furi_string_get_cstr(candidate), step);
  645. #endif
  646. stream_clean(stream);
  647. if(te) {
  648. stream_write_format(
  649. stream,
  650. subbrute_key_file_start_with_tail,
  651. frequency,
  652. subbrute_protocol_preset(preset),
  653. subbrute_protocol_file(file),
  654. bits,
  655. furi_string_get_cstr(candidate),
  656. te,
  657. repeat);
  658. } else {
  659. stream_write_format(
  660. stream,
  661. subbrute_key_file_start_no_tail,
  662. frequency,
  663. subbrute_protocol_preset(preset),
  664. subbrute_protocol_file(file),
  665. bits,
  666. furi_string_get_cstr(candidate),
  667. repeat);
  668. }
  669. furi_string_free(candidate);
  670. }
  671. void subbrute_protocol_file_generate_file(
  672. Stream* stream,
  673. uint32_t frequency,
  674. FuriHalSubGhzPreset preset,
  675. SubBruteFileProtocol file,
  676. uint64_t step,
  677. uint8_t bits,
  678. uint32_t te,
  679. uint8_t repeat,
  680. uint8_t bit_index,
  681. uint64_t file_key,
  682. bool two_bytes) {
  683. FuriString* candidate = furi_string_alloc();
  684. // char subbrute_payload_byte[8];
  685. //furi_string_set_str(candidate, file_key);
  686. subbrute_protocol_create_candidate_for_existing_file(
  687. candidate, step, bit_index, file_key, two_bytes);
  688. stream_clean(stream);
  689. if(te) {
  690. stream_write_format(
  691. stream,
  692. subbrute_key_file_start_with_tail,
  693. frequency,
  694. subbrute_protocol_preset(preset),
  695. subbrute_protocol_file(file),
  696. bits,
  697. furi_string_get_cstr(candidate),
  698. te,
  699. repeat);
  700. } else {
  701. stream_write_format(
  702. stream,
  703. subbrute_key_file_start_no_tail,
  704. frequency,
  705. subbrute_protocol_preset(preset),
  706. subbrute_protocol_file(file),
  707. bits,
  708. furi_string_get_cstr(candidate),
  709. repeat);
  710. }
  711. furi_string_free(candidate);
  712. }
  713. uint64_t
  714. subbrute_protocol_calc_max_value(SubBruteAttacks attack_type, uint8_t bits, bool two_bytes) {
  715. uint64_t max_value;
  716. if(attack_type == SubBruteAttackLoadFile) {
  717. max_value = two_bytes ? 0xFFFF : 0xFF;
  718. } else if(
  719. attack_type == SubBruteAttackSMC532624bit330 ||
  720. attack_type == SubBruteAttackSMC532624bit433 ||
  721. attack_type == SubBruteAttackUNILARM24bit330 ||
  722. attack_type == SubBruteAttackUNILARM24bit433 ||
  723. attack_type == SubBruteAttackPT226024bit315 ||
  724. attack_type == SubBruteAttackPT226024bit330 ||
  725. attack_type == SubBruteAttackPT226024bit390 ||
  726. attack_type == SubBruteAttackPT226024bit433) {
  727. max_value = 6561;
  728. } else {
  729. FuriString* max_value_s;
  730. max_value_s = furi_string_alloc();
  731. for(uint8_t i = 0; i < bits; i++) {
  732. furi_string_cat_printf(max_value_s, "1");
  733. }
  734. max_value = (uint64_t)strtol(furi_string_get_cstr(max_value_s), NULL, 2);
  735. furi_string_free(max_value_s);
  736. }
  737. return max_value;
  738. }