subbrute_protocols.c 24 KB

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