无聊的时候写的程序,很难用,但是功能很多,多到你想不到.
语法:
1. API格式:[动态库] [函数名(c调用请在前面加c)] [参数1,参数2,...]
2. 字符串格式:s + 字符串
3. 数值:i + 数值
4. 开辟空间: n (100B)
5. 引用返回值:r + 第n个(n<1000)
6. C调用函数前要加c(进行堆栈恢复)
#include <windows.h>
#include <iostream>
#include <vector>
using namespace std;
struct stApi
{
char szApi[100];
};
vector<stApi> cApiVec;
DWORD lpRetAddress = 0;
int nRetNum = 0;
DWORD dwRetValue[1000];
void ApiText(char *lpszApi)
{
int nLen = strlen(lpszApi);
stApi stApi1;
for( int i = 0, j = 0; i < nLen; i++){
if( lpszApi[i] != ' '){
stApi1.szApi[j++] = lpszApi[i];
}
else{
stApi1.szApi[j] = 0;
cApiVec.push_back(stApi1);
memset(stApi1.szApi, 0, 100);
j = 0;
}
}
}
void ApiPF()
{
int nStrNum = 0;
char *lpStr[100] = {NULL};
int nStatckSize = (cApiVec.size() - 2) << 2;
vector<stApi>::iterator iterend = cApiVec.end();
vector<stApi>::iterator iterbegin = cApiVec.begin();
DWORD lpAddress = 0;
HMODULE hModule = LoadLibrary(iterbegin[0].szApi);
if( cApiVec[1].szApi[0] == 'c' ){
lpAddress = (DWORD)GetProcAddress(hModule, &cApiVec[1].szApi[1]);
}
else
lpAddress = (DWORD)GetProcAddress(hModule, cApiVec[1].szApi);
if( !lpAddress ){
cout<< "找不到你要的API." <<endl <<endl;
return ;
}
iterbegin++;
for( --iterend; iterend != iterbegin ; iterend--){
if( iterend->szApi[0] == 's' ){
DWORD lpParamAddress = (DWORD)&iterend->szApi[1];
__asm
{
push lpParamAddress
}
}
else if( iterend->szApi[0] == 'i')
{
long n = atol(&iterend->szApi[1]);
_asm
{
push n
}
}
else if( iterend->szApi[0] == 'n' ){
lpStr[nStrNum] = new char[100];
char *lpAddr = lpStr[nStrNum];
_asm
{
push lpAddr
}
nStrNum++;
}
else if( iterend->szApi[0] == 'r' )
{
char szText[100];
strcpy(szText, &iterend->szApi[1]);
int n = atoi(szText);
if( n >= nRetNum ){
cout<< "找不到传递的返回值." <<endl;
return ;
}
DWORD dwValue = dwRetValue[n];
_asm
{
push dwValue
}
}
}
_asm
{
call lpAddress
mov lpRetAddress, eax
}
if( cApiVec[1].szApi[0] == 'c' ){
_asm
{
add esp, nStatckSize
}
}
FreeLibrary( hModule );
if( lpStr ){
cout<< endl <<"--------------执行结果-----------------" <<endl <<endl;
if( nStrNum > 0 ){
for(int i = 0; i < nStrNum; i++){
cout<<"第" << i + 1 << "个" << "新开辟的空间的地址为: "<< (int*)lpStr[i] <<endl;
cout<<"第" << i + 1 << "个" << "新开辟的空间的值为: "<< lpStr[i] <<endl;
}
}
cout<< cApiVec[1].szApi << "返回了: " << lpRetAddress << " ,以后可以用: r"<< nRetNum << " 引用它." <<endl ;
dwRetValue[nRetNum++] = lpRetAddress;
cout<< "---------------------------------------" <<endl<<endl;
for(int i = 0; i < nStrNum; i++)
delete[] lpStr[i];
}
}
int main()
{
char szApi[100];
while(1)
{
cout<< "输入API,格式:[动态库] [函数名(c调用请在前面加c)] [参数1,参数2,...]" <<endl;
cin.getline(szApi, 100);
strcat(szApi, " ");
ApiText(szApi);
ApiPF();
cApiVec.clear();
}
return 0;
}
语法:
1. API格式:[动态库] [函数名(c调用请在前面加c)] [参数1,参数2,...]
2. 字符串格式:s + 字符串
3. 数值:i + 数值
4. 开辟空间: n (100B)
5. 引用返回值:r + 第n个(n<1000)
6. C调用函数前要加c(进行堆栈恢复)
#include <windows.h>
#include <iostream>
#include <vector>
using namespace std;
struct stApi
{
char szApi[100];
};
vector<stApi> cApiVec;
DWORD lpRetAddress = 0;
int nRetNum = 0;
DWORD dwRetValue[1000];
void ApiText(char *lpszApi)
{
int nLen = strlen(lpszApi);
stApi stApi1;
for( int i = 0, j = 0; i < nLen; i++){
if( lpszApi[i] != ' '){
stApi1.szApi[j++] = lpszApi[i];
}
else{
stApi1.szApi[j] = 0;
cApiVec.push_back(stApi1);
memset(stApi1.szApi, 0, 100);
j = 0;
}
}
}
void ApiPF()
{
int nStrNum = 0;
char *lpStr[100] = {NULL};
int nStatckSize = (cApiVec.size() - 2) << 2;
vector<stApi>::iterator iterend = cApiVec.end();
vector<stApi>::iterator iterbegin = cApiVec.begin();
DWORD lpAddress = 0;
HMODULE hModule = LoadLibrary(iterbegin[0].szApi);
if( cApiVec[1].szApi[0] == 'c' ){
lpAddress = (DWORD)GetProcAddress(hModule, &cApiVec[1].szApi[1]);
}
else
lpAddress = (DWORD)GetProcAddress(hModule, cApiVec[1].szApi);
if( !lpAddress ){
cout<< "找不到你要的API." <<endl <<endl;
return ;
}
iterbegin++;
for( --iterend; iterend != iterbegin ; iterend--){
if( iterend->szApi[0] == 's' ){
DWORD lpParamAddress = (DWORD)&iterend->szApi[1];
__asm
{
push lpParamAddress
}
}
else if( iterend->szApi[0] == 'i')
{
long n = atol(&iterend->szApi[1]);
_asm
{
push n
}
}
else if( iterend->szApi[0] == 'n' ){
lpStr[nStrNum] = new char[100];
char *lpAddr = lpStr[nStrNum];
_asm
{
push lpAddr
}
nStrNum++;
}
else if( iterend->szApi[0] == 'r' )
{
char szText[100];
strcpy(szText, &iterend->szApi[1]);
int n = atoi(szText);
if( n >= nRetNum ){
cout<< "找不到传递的返回值." <<endl;
return ;
}
DWORD dwValue = dwRetValue[n];
_asm
{
push dwValue
}
}
}
_asm
{
call lpAddress
mov lpRetAddress, eax
}
if( cApiVec[1].szApi[0] == 'c' ){
_asm
{
add esp, nStatckSize
}
}
FreeLibrary( hModule );
if( lpStr ){
cout<< endl <<"--------------执行结果-----------------" <<endl <<endl;
if( nStrNum > 0 ){
for(int i = 0; i < nStrNum; i++){
cout<<"第" << i + 1 << "个" << "新开辟的空间的地址为: "<< (int*)lpStr[i] <<endl;
cout<<"第" << i + 1 << "个" << "新开辟的空间的值为: "<< lpStr[i] <<endl;
}
}
cout<< cApiVec[1].szApi << "返回了: " << lpRetAddress << " ,以后可以用: r"<< nRetNum << " 引用它." <<endl ;
dwRetValue[nRetNum++] = lpRetAddress;
cout<< "---------------------------------------" <<endl<<endl;
for(int i = 0; i < nStrNum; i++)
delete[] lpStr[i];
}
}
int main()
{
char szApi[100];
while(1)
{
cout<< "输入API,格式:[动态库] [函数名(c调用请在前面加c)] [参数1,参数2,...]" <<endl;
cin.getline(szApi, 100);
strcat(szApi, " ");
ApiText(szApi);
ApiPF();
cApiVec.clear();
}
return 0;
}