├── .gitignore ├── Cargo.lock ├── Cargo.toml ├── Jenkinsfile ├── LICENSE ├── readme.md └── src ├── annepro2.rs └── main.rs /.gitignore: -------------------------------------------------------------------------------- 1 | /.idea 2 | *.iml 3 | *.ips 4 | *.iws 5 | /target 6 | -------------------------------------------------------------------------------- /Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | version = 3 4 | 5 | [[package]] 6 | name = "annepro2_tools" 7 | version = "0.1.0" 8 | dependencies = [ 9 | "hidapi", 10 | "pretty-hex", 11 | "structopt", 12 | ] 13 | 14 | [[package]] 15 | name = "ansi_term" 16 | version = "0.12.1" 17 | source = "registry+https://github.com/rust-lang/crates.io-index" 18 | checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2" 19 | dependencies = [ 20 | "winapi", 21 | ] 22 | 23 | [[package]] 24 | name = "atty" 25 | version = "0.2.14" 26 | source = "registry+https://github.com/rust-lang/crates.io-index" 27 | checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" 28 | dependencies = [ 29 | "hermit-abi", 30 | "libc", 31 | "winapi", 32 | ] 33 | 34 | [[package]] 35 | name = "bitflags" 36 | version = "1.3.2" 37 | source = "registry+https://github.com/rust-lang/crates.io-index" 38 | checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" 39 | 40 | [[package]] 41 | name = "cc" 42 | version = "1.0.87" 43 | source = "registry+https://github.com/rust-lang/crates.io-index" 44 | checksum = "3286b845d0fccbdd15af433f61c5970e711987036cb468f437ff6badd70f4e24" 45 | 46 | [[package]] 47 | name = "cfg-if" 48 | version = "1.0.0" 49 | source = "registry+https://github.com/rust-lang/crates.io-index" 50 | checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" 51 | 52 | [[package]] 53 | name = "clap" 54 | version = "2.34.0" 55 | source = "registry+https://github.com/rust-lang/crates.io-index" 56 | checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c" 57 | dependencies = [ 58 | "ansi_term", 59 | "atty", 60 | "bitflags", 61 | "strsim", 62 | "textwrap", 63 | "unicode-width", 64 | "vec_map", 65 | ] 66 | 67 | [[package]] 68 | name = "heck" 69 | version = "0.3.3" 70 | source = "registry+https://github.com/rust-lang/crates.io-index" 71 | checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c" 72 | dependencies = [ 73 | "unicode-segmentation", 74 | ] 75 | 76 | [[package]] 77 | name = "hermit-abi" 78 | version = "0.1.19" 79 | source = "registry+https://github.com/rust-lang/crates.io-index" 80 | checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" 81 | dependencies = [ 82 | "libc", 83 | ] 84 | 85 | [[package]] 86 | name = "hidapi" 87 | version = "2.6.0" 88 | source = "registry+https://github.com/rust-lang/crates.io-index" 89 | checksum = "9a722fb137d008dbf264f54612457f8eb6a299efbcb0138178964a0809035d74" 90 | dependencies = [ 91 | "cc", 92 | "cfg-if", 93 | "libc", 94 | "pkg-config", 95 | "windows-sys", 96 | ] 97 | 98 | [[package]] 99 | name = "lazy_static" 100 | version = "1.4.0" 101 | source = "registry+https://github.com/rust-lang/crates.io-index" 102 | checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" 103 | 104 | [[package]] 105 | name = "libc" 106 | version = "0.2.153" 107 | source = "registry+https://github.com/rust-lang/crates.io-index" 108 | checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" 109 | 110 | [[package]] 111 | name = "pkg-config" 112 | version = "0.3.30" 113 | source = "registry+https://github.com/rust-lang/crates.io-index" 114 | checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" 115 | 116 | [[package]] 117 | name = "pretty-hex" 118 | version = "0.4.1" 119 | source = "registry+https://github.com/rust-lang/crates.io-index" 120 | checksum = "bbc83ee4a840062f368f9096d80077a9841ec117e17e7f700df81958f1451254" 121 | 122 | [[package]] 123 | name = "proc-macro-error" 124 | version = "1.0.4" 125 | source = "registry+https://github.com/rust-lang/crates.io-index" 126 | checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" 127 | dependencies = [ 128 | "proc-macro-error-attr", 129 | "proc-macro2", 130 | "quote", 131 | "syn", 132 | "version_check", 133 | ] 134 | 135 | [[package]] 136 | name = "proc-macro-error-attr" 137 | version = "1.0.4" 138 | source = "registry+https://github.com/rust-lang/crates.io-index" 139 | checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" 140 | dependencies = [ 141 | "proc-macro2", 142 | "quote", 143 | "version_check", 144 | ] 145 | 146 | [[package]] 147 | name = "proc-macro2" 148 | version = "1.0.78" 149 | source = "registry+https://github.com/rust-lang/crates.io-index" 150 | checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" 151 | dependencies = [ 152 | "unicode-ident", 153 | ] 154 | 155 | [[package]] 156 | name = "quote" 157 | version = "1.0.35" 158 | source = "registry+https://github.com/rust-lang/crates.io-index" 159 | checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" 160 | dependencies = [ 161 | "proc-macro2", 162 | ] 163 | 164 | [[package]] 165 | name = "strsim" 166 | version = "0.8.0" 167 | source = "registry+https://github.com/rust-lang/crates.io-index" 168 | checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" 169 | 170 | [[package]] 171 | name = "structopt" 172 | version = "0.3.26" 173 | source = "registry+https://github.com/rust-lang/crates.io-index" 174 | checksum = "0c6b5c64445ba8094a6ab0c3cd2ad323e07171012d9c98b0b15651daf1787a10" 175 | dependencies = [ 176 | "clap", 177 | "lazy_static", 178 | "structopt-derive", 179 | ] 180 | 181 | [[package]] 182 | name = "structopt-derive" 183 | version = "0.4.18" 184 | source = "registry+https://github.com/rust-lang/crates.io-index" 185 | checksum = "dcb5ae327f9cc13b68763b5749770cb9e048a99bd9dfdfa58d0cf05d5f64afe0" 186 | dependencies = [ 187 | "heck", 188 | "proc-macro-error", 189 | "proc-macro2", 190 | "quote", 191 | "syn", 192 | ] 193 | 194 | [[package]] 195 | name = "syn" 196 | version = "1.0.109" 197 | source = "registry+https://github.com/rust-lang/crates.io-index" 198 | checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" 199 | dependencies = [ 200 | "proc-macro2", 201 | "quote", 202 | "unicode-ident", 203 | ] 204 | 205 | [[package]] 206 | name = "textwrap" 207 | version = "0.11.0" 208 | source = "registry+https://github.com/rust-lang/crates.io-index" 209 | checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" 210 | dependencies = [ 211 | "unicode-width", 212 | ] 213 | 214 | [[package]] 215 | name = "unicode-ident" 216 | version = "1.0.12" 217 | source = "registry+https://github.com/rust-lang/crates.io-index" 218 | checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" 219 | 220 | [[package]] 221 | name = "unicode-segmentation" 222 | version = "1.11.0" 223 | source = "registry+https://github.com/rust-lang/crates.io-index" 224 | checksum = "d4c87d22b6e3f4a18d4d40ef354e97c90fcb14dd91d7dc0aa9d8a1172ebf7202" 225 | 226 | [[package]] 227 | name = "unicode-width" 228 | version = "0.1.11" 229 | source = "registry+https://github.com/rust-lang/crates.io-index" 230 | checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85" 231 | 232 | [[package]] 233 | name = "vec_map" 234 | version = "0.8.2" 235 | source = "registry+https://github.com/rust-lang/crates.io-index" 236 | checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" 237 | 238 | [[package]] 239 | name = "version_check" 240 | version = "0.9.4" 241 | source = "registry+https://github.com/rust-lang/crates.io-index" 242 | checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" 243 | 244 | [[package]] 245 | name = "winapi" 246 | version = "0.3.9" 247 | source = "registry+https://github.com/rust-lang/crates.io-index" 248 | checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" 249 | dependencies = [ 250 | "winapi-i686-pc-windows-gnu", 251 | "winapi-x86_64-pc-windows-gnu", 252 | ] 253 | 254 | [[package]] 255 | name = "winapi-i686-pc-windows-gnu" 256 | version = "0.4.0" 257 | source = "registry+https://github.com/rust-lang/crates.io-index" 258 | checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" 259 | 260 | [[package]] 261 | name = "winapi-x86_64-pc-windows-gnu" 262 | version = "0.4.0" 263 | source = "registry+https://github.com/rust-lang/crates.io-index" 264 | checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" 265 | 266 | [[package]] 267 | name = "windows-sys" 268 | version = "0.48.0" 269 | source = "registry+https://github.com/rust-lang/crates.io-index" 270 | checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" 271 | dependencies = [ 272 | "windows-targets", 273 | ] 274 | 275 | [[package]] 276 | name = "windows-targets" 277 | version = "0.48.5" 278 | source = "registry+https://github.com/rust-lang/crates.io-index" 279 | checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" 280 | dependencies = [ 281 | "windows_aarch64_gnullvm", 282 | "windows_aarch64_msvc", 283 | "windows_i686_gnu", 284 | "windows_i686_msvc", 285 | "windows_x86_64_gnu", 286 | "windows_x86_64_gnullvm", 287 | "windows_x86_64_msvc", 288 | ] 289 | 290 | [[package]] 291 | name = "windows_aarch64_gnullvm" 292 | version = "0.48.5" 293 | source = "registry+https://github.com/rust-lang/crates.io-index" 294 | checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" 295 | 296 | [[package]] 297 | name = "windows_aarch64_msvc" 298 | version = "0.48.5" 299 | source = "registry+https://github.com/rust-lang/crates.io-index" 300 | checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" 301 | 302 | [[package]] 303 | name = "windows_i686_gnu" 304 | version = "0.48.5" 305 | source = "registry+https://github.com/rust-lang/crates.io-index" 306 | checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" 307 | 308 | [[package]] 309 | name = "windows_i686_msvc" 310 | version = "0.48.5" 311 | source = "registry+https://github.com/rust-lang/crates.io-index" 312 | checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" 313 | 314 | [[package]] 315 | name = "windows_x86_64_gnu" 316 | version = "0.48.5" 317 | source = "registry+https://github.com/rust-lang/crates.io-index" 318 | checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" 319 | 320 | [[package]] 321 | name = "windows_x86_64_gnullvm" 322 | version = "0.48.5" 323 | source = "registry+https://github.com/rust-lang/crates.io-index" 324 | checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" 325 | 326 | [[package]] 327 | name = "windows_x86_64_msvc" 328 | version = "0.48.5" 329 | source = "registry+https://github.com/rust-lang/crates.io-index" 330 | checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" 331 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "annepro2_tools" 3 | version = "0.1.1" 4 | authors = ["codetector "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | hidapi = { version = "2.6.0", default-features = false, features = ["linux-static-libusb"] } 11 | pretty-hex = "0.4.1" 12 | structopt = "0.3.26" 13 | -------------------------------------------------------------------------------- /Jenkinsfile: -------------------------------------------------------------------------------- 1 | pipeline { 2 | agent none 3 | stages { 4 | stage('Compile Check') { 5 | agent { 6 | label "linux && rust" 7 | } 8 | steps { 9 | checkout scm 10 | sh '''cargo clean''' 11 | sh '''cargo build''' 12 | } 13 | } 14 | 15 | stage("Build Release") { 16 | parallel { 17 | stage('Build Release Linux') { 18 | agent { 19 | label "linux && rust" 20 | } 21 | 22 | steps { 23 | // Linux build part 24 | checkout scm 25 | sh '''cargo clean''' 26 | sh '''cargo build --release''' 27 | sh '''cp target/release/annepro2_tools target/release/annepro2_tools_linux_x64''' 28 | } 29 | 30 | post { 31 | always { 32 | archiveArtifacts artifacts: 'target/release/annepro2_tools_linux_x64', caseSensitive: false, fingerprint: true, followSymlinks: false, onlyIfSuccessful: true 33 | } 34 | } 35 | } 36 | stage('Build Release Windows x64') { 37 | agent { 38 | label "win32 && rust" 39 | } 40 | 41 | steps { 42 | // Linux build part 43 | checkout scm 44 | bat '''cargo clean''' 45 | bat '''cargo build --release''' 46 | bat '''ren target\\release\\annepro2_tools.exe annepro2_tools_x64.exe''' 47 | } 48 | 49 | post { 50 | always { 51 | archiveArtifacts artifacts: 'target/release/annepro2_tools_x64.exe', caseSensitive: false, fingerprint: true, followSymlinks: false, onlyIfSuccessful: true 52 | } 53 | } 54 | } 55 | stage('Build Release Windows i386') { 56 | agent { 57 | label "win32 && rust" 58 | } 59 | 60 | steps { 61 | // Linux build part 62 | checkout scm 63 | bat '''cargo clean''' 64 | bat '''cargo build --release --target=i686-pc-windows-msvc''' 65 | bat '''ren target\\i686-pc-windows-msvc\\release\\annepro2_tools.exe annepro2_tools_x86.exe''' 66 | } 67 | 68 | post { 69 | always { 70 | archiveArtifacts artifacts: 'target/i686-pc-windows-msvc/release/annepro2_tools_x86.exe', caseSensitive: false, fingerprint: true, followSymlinks: false, onlyIfSuccessful: true 71 | } 72 | } 73 | } 74 | } 75 | } 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | 294 | Copyright (C) 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | , 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # Anne Pro 2 Tools 2 | 3 | This is an alternative firmware update tool for the Anne Pro 2. 4 | It allows you to flash custom firmware onto the Anne Pro 2. 5 | Currently only the main MCU has been tested to work. 6 | 7 | Please put the keyboard into IAP mode by holding down `esc` while 8 | plugging it in to the computer before running this tool. 9 | 10 | To build 11 | ```bash 12 | cargo build --release 13 | ``` 14 | 15 | To flash file called a.bin you can invoke 16 | 17 | ```bash 18 | ./target/release/annepro2_tools a.bin 19 | ``` 20 | 21 | By default, the flasher will look for 04d9:8008 (Default Anne Pro 2 IAP) 22 | and flash binary starting at 0x4000. -------------------------------------------------------------------------------- /src/annepro2.rs: -------------------------------------------------------------------------------- 1 | use hidapi::{HidApi, HidDevice, HidResult}; 2 | use std::{thread, time::Duration}; 3 | 4 | const ANNEPRO2_VID: u16 = 0x04d9; 5 | 6 | const PID_C15: u16 = 0x8008; 7 | const PID_C18: u16 = 0x8009; 8 | 9 | #[repr(u8)] 10 | #[derive(Debug, Copy, Clone)] 11 | pub enum AP2Target { 12 | UsbHost = 1, 13 | BleHost = 2, 14 | McuMain = 3, 15 | McuLed = 4, 16 | McuBle = 5, 17 | } 18 | 19 | #[repr(u8)] 20 | #[derive(Debug, Copy, Clone)] 21 | pub enum L2Command { 22 | GLOBAL = 1, 23 | FW = 2, 24 | KEYBOARD = 16, 25 | LED = 32, 26 | MACRO = 48, 27 | BLE = 64, 28 | } 29 | 30 | #[repr(u8)] 31 | #[derive(Debug, Copy, Clone)] 32 | pub enum KeyCommand { 33 | Reserved = 0, 34 | IapMode = 1, 35 | IapGetMode = 2, 36 | IapGetFwVersion = 3, 37 | IapWirteMemory = 49, 38 | // 0x31 39 | IapWriteApFlag = 50, 40 | // 0x32 41 | IapEraseMemory = 67, // 0x43 42 | } 43 | 44 | #[derive(Debug, Copy, Clone)] 45 | pub enum AP2FlashError { 46 | NoDeviceFound, 47 | MultipleDeviceFound, 48 | USBError, 49 | EraseError, 50 | FlashError, 51 | OtherError, 52 | } 53 | 54 | pub fn flash_firmware( 55 | target: AP2Target, 56 | base: u32, 57 | file: &mut R, 58 | boot: bool, 59 | ) -> std::result::Result<(), AP2FlashError> { 60 | let mut api = HidApi::new().map_err(|_| AP2FlashError::USBError)?; 61 | 62 | let (_, mut flash_device) = fetch_devices(&api); 63 | 64 | if flash_device.is_none() { 65 | println!("Please put your keyboard into IAP mode by disconnecting it and reconnecting it while holding the ESC key."); 66 | 67 | let mut i = 10; 68 | while i > 0 { 69 | api = HidApi::new().map_err(|_| AP2FlashError::USBError)?; 70 | (_, flash_device) = fetch_devices(&api); 71 | if flash_device.is_none() { 72 | println!("Attempt in {} seconds.", i); 73 | thread::sleep(Duration::from_secs(1)); 74 | i -= 1; 75 | } else { 76 | break; 77 | } 78 | } 79 | } 80 | 81 | let (_, flash_device) = fetch_devices(&api); 82 | 83 | let dev = flash_device.expect("No device found."); 84 | 85 | let handle = api.open_path(dev.path()).expect("unable to open device"); 86 | handle.set_blocking_mode(true).expect("non-blocking"); 87 | println!( 88 | "device is {:?}", 89 | handle.get_product_string().expect("string") 90 | ); 91 | 92 | // Flashing Code 93 | erase_device(&handle, target, base).map_err(|err| { 94 | println!("Error while erasing: {}", err); 95 | AP2FlashError::USBError 96 | })?; 97 | flash_file(&handle, target, base, file); 98 | write_ap_flag(&handle, 2).map_err(|e| { 99 | println!("Error while writing AP flag: {:?}", e); 100 | AP2FlashError::USBError 101 | })?; 102 | if boot { 103 | boot_device(&handle).map_err(|e| { 104 | println!("Error while booting device: {:?}", e); 105 | AP2FlashError::USBError 106 | })?; 107 | } 108 | Ok(()) 109 | } 110 | 111 | fn fetch_devices(api: &HidApi) -> (Vec<&hidapi::DeviceInfo>, Option<&hidapi::DeviceInfo>) { 112 | 113 | for dev in api.device_list() { 114 | println!( 115 | "HID Dev: {:04x}:{:04x} {}", 116 | dev.vendor_id(), 117 | dev.product_id(), 118 | dev.product_string() 119 | .map(|it| format!("({:})", it.replace('\n', " - "))) 120 | .unwrap_or_default() 121 | ); 122 | } 123 | let anne_devices = api 124 | .device_list() 125 | .filter(|dev| dev.vendor_id() == ANNEPRO2_VID) 126 | .collect::>(); 127 | 128 | let flash_device = anne_devices.iter().find(|dev| { 129 | (dev.product_id() == PID_C15 && dev.interface_number() == 1) 130 | || (dev.product_id() == PID_C18) 131 | }); 132 | (anne_devices.clone(), flash_device.cloned()) 133 | } 134 | 135 | pub fn write_ap_flag(handle: &HidDevice, flag: u8) -> HidResult<()> { 136 | let buffer: Vec = vec![L2Command::FW as u8, KeyCommand::IapWriteApFlag as u8, flag]; 137 | write_to_target(handle, AP2Target::McuMain, &buffer)?; 138 | Ok(()) 139 | } 140 | 141 | pub fn flash_file( 142 | handle: &HidDevice, 143 | target: AP2Target, 144 | base: u32, 145 | file: &mut F, 146 | ) { 147 | let chunk_size = match &target { 148 | AP2Target::McuBle => 32usize, 149 | _ => 48usize, 150 | }; 151 | let mut current_addr = base; 152 | loop { 153 | let mut buffer = vec![0u8; chunk_size]; 154 | let size = file.read(&mut buffer).expect("read file failure"); 155 | 156 | if size > 0 { 157 | let result = write_chunk(handle, target, current_addr, &buffer); 158 | if result.is_err() { 159 | println!( 160 | "[WARNING] Error {:?} occurred during write at {:#08x}, continuing...", 161 | result.unwrap_err(), 162 | current_addr 163 | ); 164 | } else { 165 | println!( 166 | "[INFO] Wrote {} bytes, at {:#08x}, total: {} bytes written", 167 | size, 168 | current_addr, 169 | (current_addr + size as u32) - base 170 | ); 171 | } 172 | current_addr += size as u32; 173 | } 174 | 175 | if size < chunk_size { 176 | break; 177 | } 178 | } 179 | } 180 | 181 | pub fn write_chunk( 182 | handle: &HidDevice, 183 | target: AP2Target, 184 | addr: u32, 185 | chunk: &[u8], 186 | ) -> HidResult<()> { 187 | let mut buffer: Vec = vec![L2Command::FW as u8, KeyCommand::IapWirteMemory as u8]; 188 | let addr_slice: [u8; 4] = addr.to_le_bytes(); 189 | buffer.extend_from_slice(&addr_slice); 190 | buffer.extend_from_slice(chunk); 191 | write_to_target(handle, target, &buffer).map(|_| ()) 192 | } 193 | 194 | pub fn erase_device(handle: &HidDevice, target: AP2Target, addr: u32) -> HidResult<()> { 195 | let mut buffer: Vec = vec![L2Command::FW as u8, KeyCommand::IapEraseMemory as u8]; 196 | let addr_slice: [u8; 4] = addr.to_le_bytes(); 197 | buffer.extend_from_slice(&addr_slice); 198 | 199 | write_to_target(handle, target, &buffer)?; 200 | Ok(()) 201 | } 202 | 203 | pub fn boot_device(handle: &HidDevice) -> HidResult<()> { 204 | let buffer: Vec = vec![ 205 | 0x00, 0x7b, 0x10, 0x31, 0x10, 0x03, 0x00, 0x00, 0x7d, 0x02, 0x01, 0x02, 206 | ]; 207 | 208 | // directly use write because we shouldn't pad this command to 64 bytes 209 | let lol = handle.write(&buffer); 210 | 211 | if lol.is_err() { 212 | println!("err: {:?}", lol.unwrap_err()); 213 | } 214 | 215 | Ok(()) 216 | } 217 | 218 | pub fn write_to_target(handle: &HidDevice, target: AP2Target, payload: &[u8]) -> HidResult { 219 | let mut buffer: Vec = Vec::with_capacity(64); 220 | buffer.push(0x7b); 221 | buffer.push(0x10); 222 | buffer.push((((target as u8) & 0xF) << 4) | AP2Target::UsbHost as u8); 223 | buffer.push(0x10); 224 | buffer.push(payload.len() as u8); 225 | buffer.push(0); 226 | buffer.push(0); 227 | buffer.push(0x7d); 228 | buffer.extend_from_slice(payload); 229 | if buffer.len() > 64 { 230 | panic!("Wut?"); 231 | } 232 | // Pad to 64 bytes 233 | while buffer.len() < 64 { 234 | buffer.push(0); 235 | } 236 | 237 | buffer.insert(0, 0); // First word is report id. 238 | 239 | let lol = handle.write(&buffer); 240 | 241 | if lol.is_err() { 242 | let err = lol.as_ref().unwrap_err(); 243 | println!("err: {:?}", err); 244 | } 245 | 246 | let mut buf: Vec = vec![0u8; 64]; 247 | if let Err(err) = handle.read(&mut buf) { 248 | println!("err: {:?}", err); 249 | }; 250 | 251 | use pretty_hex::*; 252 | println!("read back: {:#?}", buf[0..].as_ref().hex_dump()); 253 | 254 | lol 255 | } 256 | -------------------------------------------------------------------------------- /src/main.rs: -------------------------------------------------------------------------------- 1 | use crate::annepro2::AP2Target; 2 | use std::fs::File; 3 | use std::num::ParseIntError; 4 | use std::path::PathBuf; 5 | use structopt::StructOpt; 6 | 7 | pub mod annepro2; 8 | 9 | fn parse_hex(src: &str) -> std::result::Result { 10 | if let Some(num) = src.strip_prefix("0x") { 11 | u32::from_str_radix(num, 16) 12 | } else { 13 | u32::from_str_radix(src, 16) 14 | } 15 | } 16 | 17 | #[derive(StructOpt, Debug)] 18 | #[structopt(name = "annepro2_tools")] 19 | struct ArgOpts { 20 | #[structopt(long, parse(try_from_str = parse_hex), default_value = "0x4000")] 21 | base: u32, 22 | #[structopt(long = "boot")] 23 | boot: bool, 24 | #[structopt(short = "t", long, default_value = "main")] 25 | target: String, 26 | /// File to be flashed onto device 27 | #[structopt(name = "file", parse(from_os_str))] 28 | file: PathBuf, 29 | } 30 | 31 | fn main() { 32 | let args: ArgOpts = ArgOpts::from_args(); 33 | println!("args: {:#x?}", args); 34 | let mut file = File::open(args.file).expect("invalid file"); 35 | let target; 36 | if args.target.eq_ignore_ascii_case("ble") { 37 | target = AP2Target::McuBle; 38 | } else if args.target.eq_ignore_ascii_case("main") { 39 | target = AP2Target::McuMain; 40 | } else if args.target.eq_ignore_ascii_case("led") { 41 | target = AP2Target::McuLed; 42 | } else { 43 | panic!("Invalid target, choose from main, led, and ble"); 44 | } 45 | let result = annepro2::flash_firmware(target, args.base, &mut file, args.boot); 46 | if result.is_ok() { 47 | println!("Flash complete"); 48 | if args.boot { 49 | println!("Booting Keyboard"); 50 | } 51 | } else { 52 | println!("Flash error: {:?}", result.unwrap_err()); 53 | } 54 | } 55 | --------------------------------------------------------------------------------