├── .gitattributes ├── .gitignore ├── CAPIx.cpp ├── CAPIxHelp.org ├── LICENSE ├── README.md └── bin ├── CAPIx.dll ├── CAPIxHelp.html └── cmd.exe /.gitattributes: -------------------------------------------------------------------------------- 1 | *.html linguist-language=c++ 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files 2 | *.slo 3 | *.lo 4 | *.o 5 | *.obj 6 | 7 | # Precompiled Headers 8 | *.gch 9 | *.pch 10 | 11 | # Compiled Dynamic libraries 12 | *.so 13 | *.dylib 14 | *.dll 15 | 16 | # Fortran module files 17 | *.mod 18 | *.smod 19 | 20 | # Compiled Static libraries 21 | *.lai 22 | *.la 23 | *.a 24 | *.lib 25 | 26 | # Executables 27 | *.exe 28 | *.out 29 | *.app 30 | -------------------------------------------------------------------------------- /CAPIx.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aloxaf/CAPIx/be0ec5a4ba361ece346b9574dd695dc7a94fcd1f/CAPIx.cpp -------------------------------------------------------------------------------- /CAPIxHelp.org: -------------------------------------------------------------------------------- 1 | #+TITLE: CAPIx 2.0 帮助 2 | #+AUTHOR: aiwozhonghuaba 3 | #+OPTIONS: ^:{} 4 | 5 | * 简介 6 | 致敬D大和他的CAPI(注入版) 7 | 8 | 简介: 9 | 10 | CAPI是bathome的defanvie开发的一款第三方,堪称批处理第三方的登峰造极之作 11 | 12 | CAPI提供的最大功能就是一个:调用系统API 除此之外,CAPI并没有任何功能 13 | 14 | 而且其注入式的特点,一方面使得其调用速度得到了飞一般的提升,另一方面也使得其能够保存进程数据 15 | 16 | 这两个功能,赋予了CAPI无穷的力量 17 | 18 | 何为系统API?简而言之,是MS为了便利开发者,而封装在dll中的一系列函数 19 | 20 | 通过这些函数,开发者可以不需要理解系统的内部原理就方便地开发出产品 21 | 22 | 比如著名的image(第一代),就是调用了gdi32中的API从而实现了绘图功能 23 | 24 | 而利用CAPI,我们可以轻松地实现这个功能,而且由于CAPI是注入式的,我们可以甚至可以实现双缓冲 25 | 26 | 即先把图片画到内存中的画布上,等待所有的图片都绘制完成,再将整块画布复制到CMD中 27 | 28 | 这样做的最大好处就是可以避免闪烁,实现流畅地绘制 29 | 30 | 31 | 然而CAPI有几个问题,导致了它虽然强大,但却很少被使用 32 | 33 | 1.采取远程线程注入的方法将dll注入到cmd中,这是病毒的常用伎俩,因此误杀率极高 34 | 35 | 2.开发者defanvie已经很久没有现身,而且CAPI没有开源.已经无法在最新的系统上运行了 36 | 37 | 38 | CAPIx就是为了解决这两个问题而开发的 39 | 40 | 首先CAPIx摒弃了远程线程注入的方式,而是使用一个修改过的提取自win 2003的cmd 41 | 42 | 这个cmd在启动时会自动加载CAPIx.dll,免去了注入的危险 43 | 44 | 其次CAPIx的开发者是可以联系到的,而且CAPIx完全开源,这为修复bug和增加功能提供了方便 45 | 46 | 并且CAPIx在API调用的功能上做出了进一步的加强 47 | 48 | 在API Call之外又提供了一个新命令API Exec,用来调用遵循__cdecl约定的函数 49 | 50 | 简而言之,可以调用其他dll中的函数,比如msvcrt中的大部分函数,像printf, scanf之类的 51 | 52 | 又比如调用regex2.dll实现正则匹配,还可以自己写dll供Exec调用,比如写一个浮点运算的dll代替set/a之类的 53 | 54 | CAPIx潜力无限! 55 | 56 | 下载地址: https://github.com/YinTianliang/CAPIx/tree/master/bin 57 | 58 | 请务必下载CAPIx.dll和cmd.exe, CAPIx_Help.html为详细帮助,建议下载 59 | 60 | 使用CAPIx进行的程序只能在上面这个cmd.exe中正常运行 61 | 62 | 所以建议使用以下JS启动游戏(该cmd.exe需要与js, capix.dll放在同一目录下) 63 | 64 | #+begin_src js -n 65 | new ActiveXObject('WScript.Shell').Run('"' + WScript.ScriptFullName.replace(/[^\\]*$/,'') + 'cmd.exe" /c 游戏主程序.bat') 66 | #+end_src 67 | 68 | 或者在批处理开头加上这两行 69 | 70 | #+begin_src bat -n 71 | %1@start "" "%~dp0cmd.exe" "/c %~fs0 :" 72 | %1@exit 73 | #+end_src 74 | 75 | 为了兼容以前的的CAPI作品, CAPIx的语法和CAPI是一样的, 只是在此基础之上做了加强, 使之更加人性化 76 | 77 | 本文档中的大部分内容来自http://www.bathome.net/thread-19238-1-1.html 78 | 79 | * 标识符 80 | 标识符用来添加在参数前面, 指定这个参数的类型 81 | | | | <6> | 82 | | 符号 | 大小 | 意义 | 83 | |------+------+-------------| 84 | | . | 1B | 字节 | 85 | | : | 2B | 短整形 | 86 | | ; | 4B | 长整形 | 87 | | ~ | 4B | 浮点型 | 88 | | ` | 8B | 双浮点型 | 89 | | # | - | 字符串(ANSI) | 90 | | $ | - | 字符串(Unicode) | 91 | | * | 4B | 变量(的地址),相当于C语言中的&.可以后跟"; # $ "表示这个指针指向的变量的类型,默认为$ | 92 | | @ | - | 移动指针,后跟欲移动的距离,可以为负 | 93 | 94 | * 基本命令 95 | 96 | ** Mem 97 | *** Alloc 98 | Mem Alloc [size] 99 | + 用途:申请一块内存 100 | + 参数:[size]为该内存块的大小 101 | + 返回值:该内存块的地址 102 | + 注意:内存不用时需要释放, 避免造成内存泄漏 103 | *** Free 104 | Mem Free [addr] 105 | + 用途:释放一块内存 106 | + 参数:[addr]为欲释放的内存地址 107 | *** Put 108 | Mem Put [s][addr] [s][data] [s][data] ... 109 | + 用途:将数据按格式写入内存地址中 110 | + 参数:[s][addr]为欲写入的地址, [s]可选"; *". [s][data]为欲写入的数据, [s]可选". : ; ~ ` # $ * @" 111 | + 注意:写入的数据量若超过该内存块的大小可能导致cmd崩溃 112 | *** Print 113 | Mem Print [s][addr] [s][var] [s][var] ... 114 | + 用途:将指定地址处的内容输出到变量中 115 | + 参数:[s][addr]为内存地址, [s]可选"; *". [s][var]为输出参数, [s]可选". : ; ~ ` # $ * @", [var]为变量名 116 | *** Copy 117 | Mem Copy [s][dst] [s][src] [sz] 118 | + 用途:将源地址的一段内存复制到目标地址 119 | + 参数:[s]可选"; *" 120 | 121 | *** 用途 122 | Mem系列的命令提供了对内存的操作,其最大的意义就在于实现结构体或数组 123 | 124 | 使用时要注意结构体的对齐 125 | ** API 126 | *** Call 127 | API Call [dll] [s][API] [s][data] [s][data] ... 128 | + 用途:调用遵循__stdcall约定的函数(一般为WINAPI) 129 | + 参数:[dll]为dll相对路径, [API]为API函数全名, [s]为返回值类型, 默认为";", 可选"~ `". [s][data]为参数, [s]可选"; ~ ` $ # *" 130 | + 返回值:该API的返回值 131 | *** Exec 132 | API Exec [dll] [s][API] [s][data] [s][data] ... 133 | + 用途:调用遵循__cdecl约定的函数(一般除WINAPI以外都是) 134 | *** 注 135 | API是可以指定返回值类型的 136 | 137 | 以上两个命令的[s][API]可以用该函数在内存中对应的地址来表示,此时[dll]应为"0" 138 | 139 | 如set CAPI=API Exec 0 16777215 ;0 ;1 140 | 141 | ** CAPIDll 142 | - CAPIll /? :: 返回CAPIx的基本信息 143 | - CAPIDll Ver :: 返回CAPIx的版本, 保存在变量CAPI_Ret中 144 | 145 | ** Var 146 | *** SetCall 147 | 148 | - SetCall Enable :: 开启SetCall调用方式,即set CAPI=xxxx,返回值在变量CAPI_Re中t 149 | - SetCall Disable :: 关闭SetCall调用方式(默认开启) 150 | *** GetCall 151 | - GetCall Enable :: 开启GetCall调用方式,即echo %CAPI xxx%,返回值即%CAPI xxx%扩展的结果 152 | - GetCall Disable :: 关闭GetCall调用方式 153 | 154 | * 实例 155 | ** Mem Alloc Free 156 | #+BEGIN_SRC bat -n 157 | @echo off 158 | set "CAPI=Mem Alloc 4" 159 | set "lpAddress=%CAPI_Ret%" 160 | echo %lpAddress% 161 | pause 162 | set "CAPI=Mem Free %lpAddress%" 163 | pause 164 | #+END_SRC 165 | 创建了一块大小为4的内存,内存地址保存在lpAddress里\\ 166 | 在批处理第一次暂停时,使用工具查看cmd.exe内存,可以看到在输出的地址处为4个空白字节的内存,第二次pause时,可以看到内存已经被释放 167 | ** Mem Put 168 | #+BEGIN_SRC bat -n 169 | @echo off 170 | set var=hello 171 | set data=0123456789 172 | set "CAPI=Mem Put *data .97 @1 :25105 #ab $ab *var" 173 | echo %data% 174 | pause 175 | #+END_SRC 176 | 执行前data变量的内存内容为30 00 31 00 32 00 33 00 34 00 35 00 36 00 37 00 38 00 39 00\\ 177 | 执行写入命令时,此时指针指向第1个字节,.97将1个字节为97写入,于是变成了61 00 31 00 ...,指针后移1位,指向第2个字节\\ 178 | @1将指针后移1位,此时指针指向第3个字节\\ 179 | :25105,此时指针指向第3个字节,将2个字节为25105写入,于是变成了61 00 62 11 32 00 ...,指针后移2位\\ 180 | #ab,此时指针指向第5位,将2个字节的ANSI字符串ab写入,于是变成了61 00 62 11 61 62 33 00 34 00 ...,指针后移2位\\ 181 | $ab,此时指针指向第7位,将4个字节的Unicode字符串ab写入,于是变成了61 00 62 11 61 62 61 00 62 00 ...,指针后移4位\\ 182 | /h*var,此时指针指向第11位,将var变量h的内容全部写入\\ 183 | ** Mem Copy 184 | #+BEGIN_SRC bat -n 185 | @echo off 186 | set var=hello 187 | set data=0123456789 188 | set "CAPI=Mem Copy *data *var 6" 189 | echo %data% 190 | pause 191 | #+END_SRC 192 | 执行时,将var变量的前4个字节复制到data变量中,即是“hel”\\ 193 | 因此输出“hel3456789” 194 | ** Mem Print 195 | #+BEGIN_SRC bat -n 196 | @echo off 197 | set var=0123456 198 | set "CAPI=Mem Print *var .output_1 @2 :output_2 @1 #output_3 $output_4" 199 | set output_ 200 | pause 201 | #+END_SRC 202 | var变量的内容为30 00 31 00 32 00 33 00 34 00 35 00 36 00\\ 203 | .output_1,此时指向第1个字节,将1字节的内容“31”放入output_1变量中,也就是48 \\ 204 | @2,此时指针指向第2个字节,将指针后移2位,此时指针指向第4个字节\\ 205 | :output_2,此时指针指向第4个字节,将2字节的内容“00 32”放入output_2变量中,也就是12800 \\ 206 | @1,此时指针指向第6个字节,将指针后移1位,此时指针指向第7个字节\\ 207 | #output_3,此时指针指向第7个字节,将接下来的内容作为ANSI字符串放入output_3变量中,也就是“33”,字符串3 \\ 208 | $output_4,此时指针指向第9个字节,将接下来的内容作为Unicode字符串放入output_4变量中,也就是“34 00 35 00 36 00”,字符串456 \\ 209 | 210 | ** API Call 211 | #+BEGIN_SRC bat -n 212 | @echo off 213 | set "data=message" 214 | set "CAPI=API Call user32 MessageBoxW ;0 *data $title ;1" 215 | echo %CAPI_Ret% 216 | pause 217 | #+END_SRC 218 | 调用API MessageBox,第一个参数为0,第二个参数为data变量的地址,第三个参数为Unicode字符串title,第四个参数为1\\ 219 | 由于CMD内部将变量data储存为Unicode,因此应使用Unicode版本的API,也就是MessageBoxW\\ 220 | (注:CAPIx的*标识符得到了增强,可以使用*#data来强制将data转换为ANSI字符串)\\ 221 | 222 | ** API Exec 223 | #+BEGIN_SRC bat -n 224 | @echo off 225 | set "data=123|456|789" 226 | set CAPI=API Exec msvcrt sscanf *#data "#%d|%^d|%d" *;_1 *;_2 227 | echo %_1% %_2% 228 | pause 229 | #+END_SRC 230 | 调用C语言库函数sscanf,该函数遵循cdecl调用协定,因此只能使用Exec调用\\ 231 | 第一个参数*#data表示取变量data的内容, 转换为ANSI字符串, 第二个参数为sscanf的Format, 第三个和第四个参数取了两个整形变量地址\\ 232 | 233 | 234 | #+begin_src bat -n 235 | @echo off 236 | set "CAPI=API Exec msvcrt `sqrt `666" 237 | echo %CAPI_Ret% 238 | pause 239 | #+end_src 240 | 调用C语言库函数sqrt,且指定返回值类型为双浮点数 241 | 242 | #+begin_src bat -n 243 | @echo off 244 | set "CAPI=API Exec msvcrt scanf "#%d %d" *;_1 *;_2" 245 | echo %_1%, %_2% 246 | pause 247 | #+end_src 248 | 调用C语言库函数scanf, *;_1 的意思是取环境变量_1的地址,将其当作整形变量传给scanf 249 | 250 | ** GetCall 251 | #+begin_src bat -n 252 | @echo offh 253 | set CAPI=Var GetCall Enable 254 | set lpAddress=%CAPI Mem Alloc 4% 255 | echo 申请的内存地址为:%lpAddress% 256 | set CAPI=Mem Free %lpAddress% 257 | pause 258 | #+end_src 259 | 260 | * CAPIx相对CAPI有哪些改进 261 | + "@"可以接受负值 262 | + 参数类型中增加了浮点数和双浮点数 263 | + 为函数返回值提供了类型 264 | + "*"可以通过后跟"; # $"来指定该变量类型 265 | + "*"不只是取变量内容, 而是取变量地址.API对该地址的修改会同步到变量中 266 | + "Exec"命令的加入 267 | + 可以运行内存中的函数 268 | * 等待加入的功能 269 | + COM调用 270 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU LESSER GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | 9 | This version of the GNU Lesser General Public License incorporates 10 | the terms and conditions of version 3 of the GNU General Public 11 | License, supplemented by the additional permissions listed below. 12 | 13 | 0. Additional Definitions. 14 | 15 | As used herein, "this License" refers to version 3 of the GNU Lesser 16 | General Public License, and the "GNU GPL" refers to version 3 of the GNU 17 | General Public License. 18 | 19 | "The Library" refers to a covered work governed by this License, 20 | other than an Application or a Combined Work as defined below. 21 | 22 | An "Application" is any work that makes use of an interface provided 23 | by the Library, but which is not otherwise based on the Library. 24 | Defining a subclass of a class defined by the Library is deemed a mode 25 | of using an interface provided by the Library. 26 | 27 | A "Combined Work" is a work produced by combining or linking an 28 | Application with the Library. The particular version of the Library 29 | with which the Combined Work was made is also called the "Linked 30 | Version". 31 | 32 | The "Minimal Corresponding Source" for a Combined Work means the 33 | Corresponding Source for the Combined Work, excluding any source code 34 | for portions of the Combined Work that, considered in isolation, are 35 | based on the Application, and not on the Linked Version. 36 | 37 | The "Corresponding Application Code" for a Combined Work means the 38 | object code and/or source code for the Application, including any data 39 | and utility programs needed for reproducing the Combined Work from the 40 | Application, but excluding the System Libraries of the Combined Work. 41 | 42 | 1. Exception to Section 3 of the GNU GPL. 43 | 44 | You may convey a covered work under sections 3 and 4 of this License 45 | without being bound by section 3 of the GNU GPL. 46 | 47 | 2. Conveying Modified Versions. 48 | 49 | If you modify a copy of the Library, and, in your modifications, a 50 | facility refers to a function or data to be supplied by an Application 51 | that uses the facility (other than as an argument passed when the 52 | facility is invoked), then you may convey a copy of the modified 53 | version: 54 | 55 | a) under this License, provided that you make a good faith effort to 56 | ensure that, in the event an Application does not supply the 57 | function or data, the facility still operates, and performs 58 | whatever part of its purpose remains meaningful, or 59 | 60 | b) under the GNU GPL, with none of the additional permissions of 61 | this License applicable to that copy. 62 | 63 | 3. Object Code Incorporating Material from Library Header Files. 64 | 65 | The object code form of an Application may incorporate material from 66 | a header file that is part of the Library. You may convey such object 67 | code under terms of your choice, provided that, if the incorporated 68 | material is not limited to numerical parameters, data structure 69 | layouts and accessors, or small macros, inline functions and templates 70 | (ten or fewer lines in length), you do both of the following: 71 | 72 | a) Give prominent notice with each copy of the object code that the 73 | Library is used in it and that the Library and its use are 74 | covered by this License. 75 | 76 | b) Accompany the object code with a copy of the GNU GPL and this license 77 | document. 78 | 79 | 4. Combined Works. 80 | 81 | You may convey a Combined Work under terms of your choice that, 82 | taken together, effectively do not restrict modification of the 83 | portions of the Library contained in the Combined Work and reverse 84 | engineering for debugging such modifications, if you also do each of 85 | the following: 86 | 87 | a) Give prominent notice with each copy of the Combined Work that 88 | the Library is used in it and that the Library and its use are 89 | covered by this License. 90 | 91 | b) Accompany the Combined Work with a copy of the GNU GPL and this license 92 | document. 93 | 94 | c) For a Combined Work that displays copyright notices during 95 | execution, include the copyright notice for the Library among 96 | these notices, as well as a reference directing the user to the 97 | copies of the GNU GPL and this license document. 98 | 99 | d) Do one of the following: 100 | 101 | 0) Convey the Minimal Corresponding Source under the terms of this 102 | License, and the Corresponding Application Code in a form 103 | suitable for, and under terms that permit, the user to 104 | recombine or relink the Application with a modified version of 105 | the Linked Version to produce a modified Combined Work, in the 106 | manner specified by section 6 of the GNU GPL for conveying 107 | Corresponding Source. 108 | 109 | 1) Use a suitable shared library mechanism for linking with the 110 | Library. A suitable mechanism is one that (a) uses at run time 111 | a copy of the Library already present on the user's computer 112 | system, and (b) will operate properly with a modified version 113 | of the Library that is interface-compatible with the Linked 114 | Version. 115 | 116 | e) Provide Installation Information, but only if you would otherwise 117 | be required to provide such information under section 6 of the 118 | GNU GPL, and only to the extent that such information is 119 | necessary to install and execute a modified version of the 120 | Combined Work produced by recombining or relinking the 121 | Application with a modified version of the Linked Version. (If 122 | you use option 4d0, the Installation Information must accompany 123 | the Minimal Corresponding Source and Corresponding Application 124 | Code. If you use option 4d1, you must provide the Installation 125 | Information in the manner specified by section 6 of the GNU GPL 126 | for conveying Corresponding Source.) 127 | 128 | 5. Combined Libraries. 129 | 130 | You may place library facilities that are a work based on the 131 | Library side by side in a single library together with other library 132 | facilities that are not Applications and are not covered by this 133 | License, and convey such a combined library under terms of your 134 | choice, if you do both of the following: 135 | 136 | a) Accompany the combined library with a copy of the same work based 137 | on the Library, uncombined with any other library facilities, 138 | conveyed under the terms of this License. 139 | 140 | b) Give prominent notice with the combined library that part of it 141 | is a work based on the Library, and explaining where to find the 142 | accompanying uncombined form of the same work. 143 | 144 | 6. Revised Versions of the GNU Lesser General Public License. 145 | 146 | The Free Software Foundation may publish revised and/or new versions 147 | of the GNU Lesser General Public License from time to time. Such new 148 | versions will be similar in spirit to the present version, but may 149 | differ in detail to address new problems or concerns. 150 | 151 | Each version is given a distinguishing version number. If the 152 | Library as you received it specifies that a certain numbered version 153 | of the GNU Lesser General Public License "or any later version" 154 | applies to it, you have the option of following the terms and 155 | conditions either of that published version or of any later version 156 | published by the Free Software Foundation. If the Library as you 157 | received it does not specify a version number of the GNU Lesser 158 | General Public License, you may choose any version of the GNU Lesser 159 | General Public License ever published by the Free Software Foundation. 160 | 161 | If the Library as you received it specifies that a proxy can decide 162 | whether future versions of the GNU Lesser General Public License shall 163 | apply, that proxy's public statement of acceptance of any version is 164 | permanent authorization for you to choose that version for the 165 | Library. 166 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |
2 |

Table of Contents

3 |
4 | 49 |
50 |
51 | 52 | 53 | # 简介 54 | 55 | 致敬D大和他的CAPI(注入版) 56 | 57 | 简介: 58 | 59 | CAPI是bathome的defanvie开发的一款第三方,堪称批处理第三方的登峰造极之作 60 | 61 | CAPI提供的最大功能就是一个:调用系统API 除此之外,CAPI并没有任何功能 62 | 63 | 而且其注入式的特点,一方面使得其调用速度得到了飞一般的提升,另一方面也使得其能够保存进程数据 64 | 65 | 这两个功能,赋予了CAPI无穷的力量 66 | 67 | 何为系统API?简而言之,是MS为了便利开发者,而封装在dll中的一系列函数 68 | 69 | 通过这些函数,开发者可以不需要理解系统的内部原理就方便地开发出产品 70 | 71 | 比如著名的image(第一代),就是调用了gdi32中的API从而实现了绘图功能 72 | 73 | 而利用CAPI,我们可以轻松地实现这个功能,而且由于CAPI是注入式的,我们可以甚至可以实现双缓冲 74 | 75 | 即先把图片画到内存中的画布上,等待所有的图片都绘制完成,再将整块画布复制到CMD中 76 | 77 | 这样做的最大好处就是可以避免闪烁,实现流畅地绘制 78 | 79 | 然而CAPI有几个问题,导致了它虽然强大,但却很少被使用 80 | 81 | 1.采取远程线程注入的方法将dll注入到cmd中,这是病毒的常用伎俩,因此误杀率极高 82 | 83 | 2.开发者defanvie已经很久没有现身,而且CAPI没有开源.已经无法在最新的系统上运行了 84 | 85 | CAPIx就是为了解决这两个问题而开发的 86 | 87 | 首先CAPIx摒弃了远程线程注入的方式,而是使用一个修改过的提取自win 2003的cmd 88 | 89 | 这个cmd在启动时会自动加载CAPIx.dll,免去了注入的危险 90 | 91 | 其次CAPIx的开发者是可以联系到的,而且CAPIx完全开源,这为修复bug和增加功能提供了方便 92 | 93 | 并且CAPIx在API调用的功能上做出了进一步的加强 94 | 95 | 在API Call之外又提供了一个新命令API Exec,用来调用遵循\_\_cdecl约定的函数 96 | 97 | 简而言之,可以调用其他dll中的函数,比如msvcrt中的大部分函数,像printf, scanf之类的 98 | 99 | 又比如调用regex2.dll实现正则匹配,还可以自己写dll供Exec调用,比如写一个浮点运算的dll代替set/a之类的 100 | 101 | CAPIx潜力无限! 102 | 103 | 下载地址: 104 | 105 | 请务必下载CAPIx.dll和cmd.exe, CAPIx\_Help.html为详细帮助,建议下载 106 | 107 | 使用CAPIx进行的程序只能在上面这个cmd.exe中正常运行 108 | 109 | 所以建议使用以下JS启动游戏(该cmd.exe需要与js, capix.dll放在同一目录下) 110 | 111 | 1 new ActiveXObject('WScript.Shell').Run('"' + WScript.ScriptFullName.replace(/[^\\]*$/,'') + 'cmd.exe" /c 游戏主程序.bat') 112 | 113 | 或者在批处理开头加上这两行 114 | 115 | 1 %1@start "" "%~dp0cmd.exe" "/c %~fs0 :" 116 | 2 %1@exit 117 | 118 | 为了兼容以前的的CAPI作品, CAPIx的语法和CAPI是一样的, 只是在此基础之上做了加强, 使之更加人性化 119 | 120 | 本文档中的大部分内容来自 121 | 122 | # 标识符 123 | 124 | 标识符用来添加在参数前面, 指定这个参数的类型 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 |
符号大小意义
.1B字节
:2B短整形
;4B长整形
~4B浮点型
\`8B双浮点型
#-字符串(ANSI)
$-字符串(Unicode)
\*4B变量(的地址),相当于C语言中的&.可以后跟"; # $ "表示这个指针指向的变量的类型,默认为$
@-移动指针,后跟欲移动的距离,可以为负
208 | 209 | # 基本命令 210 | 211 | ## Mem 212 | 213 | ### Alloc 214 | 215 | Mem Alloc [size] 216 | - 用途:申请一块内存 217 | - 参数:[size]为该内存块的大小 218 | - 返回值:该内存块的地址 219 | - 注意:内存不用时需要释放, 避免造成内存泄漏 220 | 221 | ### Free 222 | 223 | Mem Free [addr] 224 | - 用途:释放一块内存 225 | - 参数:[addr]为欲释放的内存地址 226 | 227 | ### Put 228 | 229 | Mem Put [s][addr] [s][data] [s][data] … 230 | - 用途:将数据按格式写入内存地址中 231 | - 参数:[s][addr]为欲写入的地址, [s]可选"; \*". [s][data]为欲写入的数据, [s]可选". : ; ~ \` # $ \* @" 232 | - 注意:写入的数据量若超过该内存块的大小可能导致cmd崩溃 233 | 234 | ### Print 235 | 236 | Mem Print [s][addr] [s][var] [s][var] … 237 | - 用途:将指定地址处的内容输出到变量中 238 | - 参数:[s][addr]为内存地址, [s]可选"; \*". [s][var]为输出参数, [s]可选". : ; ~ \` # $ \* @", [var]为变量名 239 | 240 | ### Copy 241 | 242 | Mem Copy [s][dst] [s][src] [sz] 243 | - 用途:将源地址的一段内存复制到目标地址 244 | - 参数:[s]可选"; \*" 245 | 246 | ### 用途 247 | 248 | Mem系列的命令提供了对内存的操作,其最大的意义就在于实现结构体或数组 249 | 250 | 使用时要注意结构体的对齐 251 | 252 | ## API 253 | 254 | ### Call 255 | 256 | API Call [dll] [s][API] [s][data] [s][data] … 257 | - 用途:调用遵循\_\_stdcall约定的函数(一般为WINAPI) 258 | - 参数:[dll]为dll相对路径, [API]为API函数全名, [s]为返回值类型, 默认为";", 可选"~ \`". [s][data]为参数, [s]可选"; ~ \` $ # \*" 259 | - 返回值:该API的返回值 260 | 261 | ### Exec 262 | 263 | API Exec [dll] [s][API] [s][data] [s][data] … 264 | - 用途:调用遵循\_\_cdecl约定的函数(一般除WINAPI以外都是) 265 | 266 | ### 注 267 | 268 | API是可以指定返回值类型的 269 | 270 | 以上两个命令的[s][API]可以用该函数在内存中对应的地址来表示,此时[dll]应为"0" 271 | 272 | 如set CAPI=API Exec 0 16777215 ;0 ;1 273 | 274 | ## CAPIDll 275 | 276 | - **CAPIll /?:** 返回CAPIx的基本信息 277 | - **CAPIDll Ver:** 返回CAPIx的版本, 保存在变量CAPI\_Ret中 278 | 279 | ## Var 280 | 281 | ### SetCall 282 | 283 | - **SetCall Enable:** 开启SetCall调用方式,即set CAPI=xxxx,返回值在变量CAPI\_Re中t 284 | - **SetCall Disable:** 关闭SetCall调用方式(默认开启) 285 | 286 | ### GetCall 287 | 288 | - **GetCall Enable:** 开启GetCall调用方式,即echo %CAPI xxx%,返回值即%CAPI xxx%扩展的结果 289 | - **GetCall Disable:** 关闭GetCall调用方式 290 | 291 | # 实例 292 | 293 | ## Mem Alloc Free 294 | 295 | 1 @echo off 296 | 2 set "CAPI=Mem Alloc 4" 297 | 3 set "lpAddress=%CAPI_Ret%" 298 | 4 echo %lpAddress% 299 | 5 pause 300 | 6 set "CAPI=Mem Free %lpAddress%" 301 | 7 pause 302 | 303 | 创建了一块大小为4的内存,内存地址保存在lpAddress里 304 | 在批处理第一次暂停时,使用工具查看cmd.exe内存,可以看到在输出的地址处为4个空白字节的内存,第二次pause时,可以看到内存已经被释放 305 | 306 | ## Mem Put 307 | 308 | 1 @echo off 309 | 2 set var=hello 310 | 3 set data=0123456789 311 | 4 set "CAPI=Mem Put *data .97 @1 :25105 #ab $ab *var" 312 | 5 echo %data% 313 | 6 pause 314 | 315 | 执行前data变量的内存内容为30 00 31 00 32 00 33 00 34 00 35 00 36 00 37 00 38 00 39 00 316 | 执行写入命令时,此时指针指向第1个字节,.97将1个字节为97写入,于是变成了61 00 31 00 …,指针后移1位,指向第2个字节 317 | @1将指针后移1位,此时指针指向第3个字节 318 | 319 | :25105,此时指针指向第3个字节,将2个字节为25105写入,于是变成了61 00 62 11 32 00 …,指针后移2位 320 | #ab,此时指针指向第5位,将2个字节的ANSI字符串ab写入,于是变成了61 00 62 11 61 62 33 00 34 00 …,指针后移2位 321 | $ab,此时指针指向第7位,将4个字节的Unicode字符串ab写入,于是变成了61 00 62 11 61 62 61 00 62 00 …,指针后移4位 322 | /h\*var,此时指针指向第11位,将var变量h的内容全部写入 323 | 324 | ## Mem Copy 325 | 326 | 1 @echo off 327 | 2 set var=hello 328 | 3 set data=0123456789 329 | 4 set "CAPI=Mem Copy *data *var 6" 330 | 5 echo %data% 331 | 6 pause 332 | 333 | 执行时,将var变量的前4个字节复制到data变量中,即是“hel” 334 | 因此输出“hel3456789” 335 | 336 | ## Mem Print 337 | 338 | 1 @echo off 339 | 2 set var=0123456 340 | 3 set "CAPI=Mem Print *var .output_1 @2 :output_2 @1 #output_3 $output_4" 341 | 4 set output_ 342 | 5 pause 343 | 344 | var变量的内容为30 00 31 00 32 00 33 00 34 00 35 00 36 00 345 | .output\_1,此时指向第1个字节,将1字节的内容“31”放入output\_1变量中,也就是48 346 | @2,此时指针指向第2个字节,将指针后移2位,此时指针指向第4个字节 347 | :output\_2,此时指针指向第4个字节,将2字节的内容“00 32”放入output\_2变量中,也就是12800 348 | @1,此时指针指向第6个字节,将指针后移1位,此时指针指向第7个字节 349 | #output\_3,此时指针指向第7个字节,将接下来的内容作为ANSI字符串放入output\_3变量中,也就是“33”,字符串3 350 | $output\_4,此时指针指向第9个字节,将接下来的内容作为Unicode字符串放入output\_4变量中,也就是“34 00 35 00 36 00”,字符串456 351 | 352 | ## API Call 353 | 354 | 1 @echo off 355 | 2 set "data=message" 356 | 3 set "CAPI=API Call user32 MessageBoxW ;0 *data $title ;1" 357 | 4 echo %CAPI_Ret% 358 | 5 pause 359 | 360 | 调用API MessageBox,第一个参数为0,第二个参数为data变量的地址,第三个参数为Unicode字符串title,第四个参数为1 361 | 由于CMD内部将变量data储存为Unicode,因此应使用Unicode版本的API,也就是MessageBoxW 362 | (注:CAPIx的\*标识符得到了增强,可以使用\*#data来强制将data转换为ANSI字符串) 363 | 364 | ## API Exec 365 | 366 | 1 @echo off 367 | 2 set "data=123|456|789" 368 | 3 set CAPI=API Exec msvcrt sscanf *#data "#%d|%^d|%d" *;_1 *;_2 369 | 4 echo %_1% %_2% 370 | 5 pause 371 | 372 | 调用C语言库函数sscanf,该函数遵循cdecl调用协定,因此只能使用Exec调用 373 | 第一个参数\*#data表示取变量data的内容, 转换为ANSI字符串, 第二个参数为sscanf的Format, 第三个和第四个参数取了两个整形变量地址 374 | 375 | 1 @echo off 376 | 2 set "CAPI=API Exec msvcrt `sqrt `666" 377 | 3 echo %CAPI_Ret% 378 | 4 pause 379 | 380 | 调用C语言库函数sqrt,且指定返回值类型为双浮点数 381 | 382 | 1 @echo off 383 | 2 set "CAPI=API Exec msvcrt scanf "#%d %d" *;_1 *;_2" 384 | 3 echo %_1%, %_2% 385 | 4 pause 386 | 387 | 调用C语言库函数scanf, \*;\_1 的意思是取环境变量\_1的地址,将其当作整形变量传给scanf 388 | 389 | ## GetCall 390 | 391 | 1 @echo offh 392 | 2 set CAPI=Var GetCall Enable 393 | 3 set lpAddress=%CAPI Mem Alloc 4% 394 | 4 echo 申请的内存地址为:%lpAddress% 395 | 5 set CAPI=Mem Free %lpAddress% 396 | 6 pause 397 | 398 | # CAPIx相对CAPI有哪些改进 399 | 400 | - "@"可以接受负值 401 | - 参数类型中增加了浮点数和双浮点数 402 | - 为函数返回值提供了类型 403 | - "\*"可以通过后跟"; # $"来指定该变量类型 404 | - "\*"不只是取变量内容, 而是取变量地址.API对该地址的修改会同步到变量中 405 | - "Exec"命令的加入 406 | - 可以运行内存中的函数 407 | 408 | # 等待加入的功能 409 | 410 | - COM调用 -------------------------------------------------------------------------------- /bin/CAPIx.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aloxaf/CAPIx/be0ec5a4ba361ece346b9574dd695dc7a94fcd1f/bin/CAPIx.dll -------------------------------------------------------------------------------- /bin/CAPIxHelp.html: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | CAPIx 2.0.1 帮助 7 | 8 | 9 | 10 | 11 | 91 | 137 | 138 | 139 |
140 |

CAPIx 2.0 帮助

141 |
142 |

Table of Contents

143 |
144 | 189 |
190 |
191 | 192 |
193 |

1 简介

194 |
195 |

196 | 致敬D大和他的CAPI(注入版) 197 |

198 | 199 |

200 | 简介: 201 |

202 | 203 |

204 | CAPI是bathome的defanvie开发的一款第三方,堪称批处理第三方的登峰造极之作 205 |

206 | 207 |

208 | CAPI提供的最大功能就是一个:调用系统API 除此之外,CAPI并没有任何功能 209 |

210 | 211 |

212 | 而且其注入式的特点,一方面使得其调用速度得到了飞一般的提升,另一方面也使得其能够保存进程数据 213 |

214 | 215 |

216 | 这两个功能,赋予了CAPI无穷的力量 217 |

218 | 219 |

220 | 何为系统API?简而言之,是MS为了便利开发者,而封装在dll中的一系列函数 221 |

222 | 223 |

224 | 通过这些函数,开发者可以不需要理解系统的内部原理就方便地开发出产品 225 |

226 | 227 |

228 | 比如著名的image(第一代),就是调用了gdi32中的API从而实现了绘图功能 229 |

230 | 231 |

232 | 而利用CAPI,我们可以轻松地实现这个功能,而且由于CAPI是注入式的,我们可以甚至可以实现双缓冲 233 |

234 | 235 |

236 | 即先把图片画到内存中的画布上,等待所有的图片都绘制完成,再将整块画布复制到CMD中 237 |

238 | 239 |

240 | 这样做的最大好处就是可以避免闪烁,实现流畅地绘制 241 |

242 | 243 | 244 |

245 | 然而CAPI有几个问题,导致了它虽然强大,但却很少被使用 246 |

247 | 248 |

249 | 1.采取远程线程注入的方法将dll注入到cmd中,这是病毒的常用伎俩,因此误杀率极高 250 |

251 | 252 |

253 | 2.开发者defanvie已经很久没有现身,而且CAPI没有开源.已经无法在最新的系统上运行了 254 |

255 | 256 | 257 |

258 | CAPIx就是为了解决这两个问题而开发的 259 |

260 | 261 |

262 | 首先CAPIx摒弃了远程线程注入的方式,而是使用一个修改过的提取自win 2003的cmd 263 |

264 | 265 |

266 | 这个cmd在启动时会自动加载CAPIx.dll,免去了注入的危险 267 |

268 | 269 |

270 | 其次CAPIx的开发者是可以联系到的,而且CAPIx完全开源,这为修复bug和增加功能提供了方便 271 |

272 | 273 |

274 | 并且CAPIx在API调用的功能上做出了进一步的加强 275 |

276 | 277 |

278 | 在API Call之外又提供了一个新命令API Exec,用来调用遵循__cdecl约定的函数 279 |

280 | 281 |

282 | 简而言之,可以调用其他dll中的函数,比如msvcrt中的大部分函数,像printf, scanf之类的 283 |

284 | 285 |

286 | 又比如调用regex2.dll实现正则匹配,还可以自己写dll供Exec调用,比如写一个浮点运算的dll代替set/a之类的 287 |

288 | 289 |

290 | CAPIx潜力无限! 291 |

292 | 293 |

294 | 下载地址: https://github.com/YinTianliang/CAPIx/tree/master/bin 295 |

296 | 297 |

298 | 请务必下载CAPIx.dll和cmd.exe, CAPIx_Help.html为详细帮助,建议下载 299 |

300 | 301 |

302 | 使用CAPIx进行的程序只能在上面这个cmd.exe中正常运行 303 |

304 | 305 |

306 | 所以建议使用以下JS启动游戏(该cmd.exe需要与js, capix.dll放在同一目录下) 307 |

308 | 309 |
310 | 311 |
1: new ActiveXObject('WScript.Shell').Run('"' + WScript.ScriptFullName.replace(/[^\\]*$/,'') + 'cmd.exe" /c 游戏主程序.bat')
312 | 
313 |
314 | 315 |

316 | 或者在批处理开头加上这两行 317 |

318 | 319 |
320 | 321 |
1: %1@start "" "%~dp0cmd.exe" "/c %~fs0 :"
322 | 2: %1@exit
323 | 
324 |
325 | 326 |

327 | 为了兼容以前的的CAPI作品, CAPIx的语法和CAPI是一样的, 只是在此基础之上做了加强, 使之更加人性化 328 |

329 | 330 |

331 | 本文档中的大部分内容来自http://www.bathome.net/thread-19238-1-1.html 332 |

333 |
334 |
335 | 336 |
337 |

2 标识符

338 |
339 |

340 | 标识符用来添加在参数前面, 指定这个参数的类型 341 |

342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 | 375 | 376 | 377 | 378 | 379 | 380 | 381 | 382 | 383 | 384 | 385 | 386 | 387 | 388 | 389 | 390 | 391 | 392 | 393 | 394 | 395 | 396 | 397 | 398 | 399 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 |
符号大小意义
.1B字节
:2B短整形
;4B长整形
~4B浮点型
`8B双浮点型
#-字符串(ANSI)
$-字符串(Unicode)
*4B变量(的地址),相当于C语言中的&.可以后跟"; # $ "表示这个指针指向的变量的类型,默认为$
@-移动指针,后跟欲移动的距离,可以为负
415 |
416 |
417 | 418 |
419 |

3 基本命令

420 |
421 |
422 |

3.1 Mem

423 |
424 |
425 |

3.1.1 Alloc

426 |
427 |

428 | Mem Alloc [size] 429 |

430 |
    431 |
  • 用途:申请一块内存 432 |
  • 433 |
  • 参数:[size]为该内存块的大小 434 |
  • 435 |
  • 返回值:该内存块的地址 436 |
  • 437 |
  • 注意:内存不用时需要释放, 避免造成内存泄漏 438 |
  • 439 |
440 |
441 |
442 |
443 |

3.1.2 Free

444 |
445 |

446 | Mem Free [addr] 447 |

448 |
    449 |
  • 用途:释放一块内存 450 |
  • 451 |
  • 参数:[addr]为欲释放的内存地址 452 |
  • 453 |
454 |
455 |
456 |
457 |

3.1.3 Put

458 |
459 |

460 | Mem Put [s][addr] [s][data] [s][data] … 461 |

462 |
    463 |
  • 用途:将数据按格式写入内存地址中 464 |
  • 465 |
  • 参数:[s][addr]为欲写入的地址, [s]可选"; *". [s][data]为欲写入的数据, [s]可选". : ; ~ ` # $ * @" 466 |
  • 467 |
  • 注意:写入的数据量若超过该内存块的大小可能导致cmd崩溃 468 |
  • 469 |
470 |
471 |
472 |
473 |

3.1.4 Print

474 |
475 |

476 | Mem Print [s][addr] [s][var] [s][var] … 477 |

478 |
    479 |
  • 用途:将指定地址处的内容输出到变量中 480 |
  • 481 |
  • 参数:[s][addr]为内存地址, [s]可选"; *". [s][var]为输出参数, [s]可选". : ; ~ ` # $ * @", [var]为变量名 482 |
  • 483 |
484 |
485 |
486 |
487 |

3.1.5 Copy

488 |
489 |

490 | Mem Copy [s][dst] [s][src] [sz] 491 |

492 |
    493 |
  • 用途:将源地址的一段内存复制到目标地址 494 |
  • 495 |
  • 参数:[s]可选"; *" 496 |
  • 497 |
498 |
499 |
500 | 501 |
502 |

3.1.6 用途

503 |
504 |

505 | Mem系列的命令提供了对内存的操作,其最大的意义就在于实现结构体或数组 506 |

507 | 508 |

509 | 使用时要注意结构体的对齐 510 |

511 |
512 |
513 |
514 |
515 |

3.2 API

516 |
517 |
518 |

3.2.1 Call

519 |
520 |

521 | API Call [dll] [s][API] [s][data] [s][data] … 522 |

523 |
    524 |
  • 用途:调用遵循__stdcall约定的函数(一般为WINAPI) 525 |
  • 526 |
  • 参数:[dll]为dll相对路径, [API]为API函数全名, [s]为返回值类型, 默认为";", 可选"~ `". [s][data]为参数, [s]可选"; ~ ` $ # *" 527 |
  • 528 |
  • 返回值:该API的返回值 529 |
  • 530 |
531 |
532 |
533 |
534 |

3.2.2 Exec

535 |
536 |

537 | API Exec [dll] [s][API] [s][data] [s][data] … 538 |

539 |
    540 |
  • 用途:调用遵循__cdecl约定的函数(一般除WINAPI以外都是) 541 |
  • 542 |
543 |
544 |
545 |
546 |

3.2.3

547 |
548 |

549 | API是可以指定返回值类型的 550 |

551 | 552 |

553 | 以上两个命令的[s][API]可以用该函数在内存中对应的地址来表示,此时[dll]应为"0" 554 |

555 | 556 |

557 | 如set CAPI=API Exec 0 16777215 ;0 ;1 558 |

559 |
560 |
561 |
562 | 563 |
564 |

3.3 CAPIDll

565 |
566 |
567 |
CAPIll /?
返回CAPIx的基本信息 568 |
569 |
CAPIDll Ver
返回CAPIx的版本, 保存在变量CAPI_Ret中 570 |
571 |
572 |
573 |
574 | 575 |
576 |

3.4 Var

577 |
578 |
579 |

3.4.1 SetCall

580 |
581 |
582 |
SetCall Enable
开启SetCall调用方式,即set CAPI=xxxx,返回值在变量CAPI_Re中t 583 |
584 |
SetCall Disable
关闭SetCall调用方式(默认开启) 585 |
586 |
587 |
588 |
589 |
590 |

3.4.2 GetCall

591 |
592 |
593 |
GetCall Enable
开启GetCall调用方式,即echo %CAPI xxx%,返回值即%CAPI xxx%扩展的结果 594 |
595 |
GetCall Disable
关闭GetCall调用方式 596 |
597 |
598 |
599 |
600 |
601 |
602 | 603 |
604 |

4 实例

605 |
606 |
607 |

4.1 Mem Alloc Free

608 |
609 |
610 | 611 |
1: @echo off
612 | 2: set "CAPI=Mem Alloc 4"
613 | 3: set "lpAddress=%CAPI_Ret%"
614 | 4: echo %lpAddress%
615 | 5: pause
616 | 6: set "CAPI=Mem Free %lpAddress%"
617 | 7: pause
618 | 
619 |
620 |

621 | 创建了一块大小为4的内存,内存地址保存在lpAddress里
622 | 在批处理第一次暂停时,使用工具查看cmd.exe内存,可以看到在输出的地址处为4个空白字节的内存,第二次pause时,可以看到内存已经被释放 623 |

624 |
625 |
626 |
627 |

4.2 Mem Put

628 |
629 |
630 | 631 |
1: @echo off
632 | 2: set var=hello
633 | 3: set data=0123456789
634 | 4: set "CAPI=Mem Put *data .97 @1 :25105 #ab $ab *var"
635 | 5: echo %data%
636 | 6: pause
637 | 
638 |
639 |

640 | 执行前data变量的内存内容为30 00 31 00 32 00 33 00 34 00 35 00 36 00 37 00 38 00 39 00
641 | 执行写入命令时,此时指针指向第1个字节,.97将1个字节为97写入,于是变成了61 00 31 00 …,指针后移1位,指向第2个字节
642 | @1将指针后移1位,此时指针指向第3个字节
643 |

644 |

645 | :25105,此时指针指向第3个字节,将2个字节为25105写入,于是变成了61 00 62 11 32 00 …,指针后移2位
646 | #ab,此时指针指向第5位,将2个字节的ANSI字符串ab写入,于是变成了61 00 62 11 61 62 33 00 34 00 …,指针后移2位
647 | $ab,此时指针指向第7位,将4个字节的Unicode字符串ab写入,于是变成了61 00 62 11 61 62 61 00 62 00 …,指针后移4位
648 | /h*var,此时指针指向第11位,将var变量h的内容全部写入
649 |

650 |
651 |
652 |
653 |

4.3 Mem Copy

654 |
655 |
656 | 657 |
1: @echo off
658 | 2: set var=hello
659 | 3: set data=0123456789
660 | 4: set "CAPI=Mem Copy *data *var 6"
661 | 5: echo %data%
662 | 6: pause
663 | 
664 |
665 |

666 | 执行时,将var变量的前4个字节复制到data变量中,即是“hel”
667 | 因此输出“hel3456789” 668 |

669 |
670 |
671 |
672 |

4.4 Mem Print

673 |
674 |
675 | 676 |
1: @echo off
677 | 2: set var=0123456
678 | 3: set "CAPI=Mem Print *var .output_1 @2 :output_2 @1 #output_3 $output_4"
679 | 4: set output_
680 | 5: pause
681 | 
682 |
683 |

684 | var变量的内容为30 00 31 00 32 00 33 00 34 00 35 00 36 00
685 | .output_1,此时指向第1个字节,将1字节的内容“31”放入output_1变量中,也就是48
686 | @2,此时指针指向第2个字节,将指针后移2位,此时指针指向第4个字节
687 | :output_2,此时指针指向第4个字节,将2字节的内容“00 32”放入output_2变量中,也就是12800
688 | @1,此时指针指向第6个字节,将指针后移1位,此时指针指向第7个字节
689 | #output_3,此时指针指向第7个字节,将接下来的内容作为ANSI字符串放入output_3变量中,也就是“33”,字符串3
690 | $output_4,此时指针指向第9个字节,将接下来的内容作为Unicode字符串放入output_4变量中,也就是“34 00 35 00 36 00”,字符串456
691 |

692 |
693 |
694 | 695 |
696 |

4.5 API Call

697 |
698 |
699 | 700 |
1: @echo off
701 | 2: set "data=message"
702 | 3: set "CAPI=API Call user32 MessageBoxW ;0 *data $title ;1"
703 | 4: echo %CAPI_Ret%
704 | 5: pause
705 | 
706 |
707 |

708 | 调用API MessageBox,第一个参数为0,第二个参数为data变量的地址,第三个参数为Unicode字符串title,第四个参数为1
709 | 由于CMD内部将变量data储存为Unicode,因此应使用Unicode版本的API,也就是MessageBoxW
710 | (注:CAPIx的*标识符得到了增强,可以使用*#data来强制将data转换为ANSI字符串)
711 |

712 |
713 |
714 | 715 |
716 |

4.6 API Exec

717 |
718 |
719 | 720 |
1: @echo off
721 | 2: set "data=123|456|789"
722 | 3: set CAPI=API Exec msvcrt sscanf *#data "#%d|%^d|%d" *;_1 *;_2
723 | 4: echo %_1%  %_2%
724 | 5: pause
725 | 
726 |
727 |

728 | 调用C语言库函数sscanf,该函数遵循cdecl调用协定,因此只能使用Exec调用
729 | 第一个参数*#data表示取变量data的内容, 转换为ANSI字符串, 第二个参数为sscanf的Format, 第三个和第四个参数取了两个整形变量地址
730 |

731 | 732 | 733 |
734 | 735 |
1: @echo off
736 | 2: set "CAPI=API Exec msvcrt `sqrt `666"
737 | 3: echo %CAPI_Ret%
738 | 4: pause
739 | 
740 |
741 |

742 | 调用C语言库函数sqrt,且指定返回值类型为双浮点数 743 |

744 | 745 |
746 | 747 |
1: @echo off
748 | 2: set "CAPI=API Exec msvcrt scanf "#%d %d" *;_1 *;_2"
749 | 3: echo %_1%, %_2%
750 | 4: pause
751 | 
752 |
753 |

754 | 调用C语言库函数scanf, *;_1 的意思是取环境变量_1的地址,将其当作整形变量传给scanf 755 |

756 |
757 |
758 | 759 |
760 |

4.7 GetCall

761 |
762 |
763 | 764 |
1: @echo offh
765 | 2: set CAPI=Var GetCall Enable
766 | 3: set lpAddress=%CAPI Mem Alloc 4%
767 | 4: echo 申请的内存地址为:%lpAddress%
768 | 5: set CAPI=Mem Free %lpAddress%
769 | 6: pause
770 | 
771 |
772 |
773 |
774 |
775 | 776 |
777 |

5 CAPIx相对CAPI有哪些改进

778 |
779 |
    780 |
  • "@"可以接受负值 781 |
  • 782 |
  • 参数类型中增加了浮点数和双浮点数 783 |
  • 784 |
  • 为函数返回值提供了类型 785 |
  • 786 |
  • "*"可以通过后跟"; # $"来指定该变量类型 787 |
  • 788 |
  • "*"不只是取变量内容, 而是取变量地址.API对该地址的修改会同步到变量中 789 |
  • 790 |
  • "Exec"命令的加入 791 |
  • 792 |
  • 可以运行内存中的函数 793 |
  • 794 |
795 |
796 |
797 |
798 |

6 等待加入的功能

799 |
800 |
    801 |
  • COM调用 802 |
  • 803 |
804 |
805 |
806 |
807 |
808 |

Author: aiwozhonghuaba

809 |

Created: 2017-02-11 Sat 19:55

810 |

Emacs 25.1.1 (Org mode 8.2.10)

811 |

Validate

812 |
813 | 814 | -------------------------------------------------------------------------------- /bin/cmd.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aloxaf/CAPIx/be0ec5a4ba361ece346b9574dd695dc7a94fcd1f/bin/cmd.exe --------------------------------------------------------------------------------