在网上找到大三写的一篇文章,保存到Blog留做纪念!
《汇编编写 可以自启动的磁盘》
下面贴出了两段代码boot.asm 和shell.asm,实现磁盘启动,并且解析了两个命令 time 和 reboot,有兴趣的朋友可以看看。
由于本人的汇编知识很菜,这篇文章只是让大家看看磁盘启动是如何实现的,如果有错误的地方,大家能够指出那就太谢谢了
步骤:放入一张磁盘,把这两段代码编译成EXE,分别执行一次,重启计算机,如果有虚拟系统环境的软件更好,如virtual PC,直接就可以看到效果。
--------------------------------------------------------------------------------
以下是boot.asm
--------------------------------------------------------------------------------
;启动代码
;-----------------------------------------------------
code_seg segment para 'code'
main proc far
assume cs:code_seg,ds:code_seg
org 00h
start:
push ds
sub ax,ax
push ax
mov ax,code_seg
mov ds,ax
mov es,ax
mov ax,0301h ;写1扇区
mov cx,0001h
mov bx,7c00h ;从代码7c00h开始
mov dx,0
int 13h
mov ax,0301h ;写2扇区,数据
mov cx,0002h
mov bx,7e00h ;从代码7e00h开始
mov dx,0
int 13h
ret
org 7c00h ;MBR开始
mov ax,0
mov es,ax
mov ax,201h
mov bx,7e00h ;把2扇区读入7e00h
mov cx,2 ;第二扇区
mov dx,0
int 13h
mov ah,6h ;清屏
mov al,26
mov bh,07h
mov cx,0
mov dh,26
mov dl,80
int 10h
mov ax,1301h ;显示文字
mov bx,04eh
mov cx,18
mov dx,0
lea bp,hello ;7e00h存放着字符串
int 10h
mov ah,3h ;换行
mov bh,0
int 10h
inc dh
mov dl,0
mov ah,2h
mov bh,0
int 10h
jmp init ;跳转到初始化代码
org 7dfeh
db 55h,0aah
org 7e00h ;数据扇区
hello db 'Loading System....'
org 7f00h ;初始化区
init:
mov ax,0
mov es,ax
mov ds,ax
mov ax,201h ;5扇区读入8000h,把命令解释器载入内存
mov bx,8000h
mov cx,5
mov dx,0
int 13h
mov ax,201h ;7扇区读入8400h,把命令处理程序
mov bx,8400h
mov cx,7
mov dx,0
int 13h
jmp command ;跳到命令解释器
org 7ffeh
db 55h,0aah
command: org 8000h
main endp
code_seg ends
end start
--------------------------------------------------------------------------------
以下是shell.asm
--------------------------------------------------------------------------------
;命令解析器
;-------------------------------------------------------------
code_seg segment para 'code'
main proc far
assume cs:code_seg,ds:code_seg
start:
push ds
sub ax,ax
push ax
mov ax,code_seg
mov ds,ax
mov es,ax
mov ax,0301h ;写5扇区
mov cx,0005h
mov bx,8000h ;从代码8000h开始
mov dx,0
int 13h
mov ax,0301h ;写7扇区数据
mov cx,0007h
mov bx,8400h ;从代码8400h开始
mov dx,0
int 13h
ret
org 8000h
kaishi: call printtsf
lea di,command ;命令输入开始
mov dx,0
push dx
begin: mov ah,0h
int 16h
cmp al,0dh ;等于回车
je finish
cmp al,08
jne sast
call backgb
jmp begin
sast: pop dx
cmp dx,13 ;命令最大14字符
ja tolong
inc dx
push dx
stosb ;存储单个字符
mov ah,9h ;打印单个字符
mov bh,0
mov bl,07h
mov cx,1
int 10h
call tuigb ;光标移动
jump1: jmp begin
tolong: push dx ;发出警告声音
mov dx,100
in al,61h
and al,11111100b
sound: xor al,2
out 61h,al
mov cx,140h
wait1: loop wait1
dec dx
jne sound
jmp begin
finish: pop dx
cmp dx,0
je nos
call scroll
nos: call check_com
jmp kaishi
main endp
;------------------------------------------------------------
command db 14 dup(' ') ;6扇区开始
messrb db 'System will reboot now!'
messnf db 'Input command isnot exit!'
tsf db '$'
comlist db 'reboot ',00h,84h
db 'time ',00h,85h
;------------------------------------------------------------
check_com proc near
lea bx,comlist ;便于定位每个命令的首地址
lea di,comlist ;命令表首地址
mov dx,2 ;指令的个数
cmpcom: lea si,command ;存储输入命令地址
cld
mov cx,14
repz cmpsb
jz match
add bx,16
mov di,bx
dec dx
jnz cmpcom
call getgb
mov ax,1301h ;显示文字mess2 NO
mov bx,07h
mov cx,25
lea bp,messnf ;no found地址
int 10h
call scroll
lea di,command ;清空command
mov cx,0014
cld
mov ax,20h
rep stosb
ret
match: add bx,14
call [bx] ;定位命令处理地址
lea di,command ;清空command
mov cx,0014
cld
mov ax,20h
rep stosb
ret
check_com endp
;-------------------------------------------------------------
scroll proc near
call getgb
cmp dh,23 ;是否到达23行
jbe scrend ;判断是否到达屏底
mov dl,0 ;到达屏底,到第1列
call setgb
mov ah,6 ;滚1行
mov al,1
mov bh,07
mov cx,0
mov dh,26
mov dl,80
int 10h
ret
scrend: call getgb
inc dh
mov dl,0
call setgb
ret
scroll endp
tuigb proc near
call getgb
inc dl
call setgb
ret
tuigb endp
;--------------------------------------------------------------
printtsf proc near
mov ah,9h ;打印单个字符$
mov al,tsf
mov bh,0
mov bl,07h
mov cx,1
int 10h
call tuigb
ret
printtsf endp
backgb proc near
call getgb
dec dl
call setgb
ret
backgb endp
getgb proc near
mov ah,3h
mov bh,0
int 10h
ret
getgb endp
setgb proc near
mov ah,2h
mov bh,0
int 10h
ret
setgb endp
org 83feh
db 55h,0aah
org 8400h
reboot proc near
call getgb
mov ax,1301h ;显示文字重启信息
mov bx,07h
mov cx,23
lea bp,messrb ;reboot字符地址
int 10h
call scroll
mov bl,0Feh ;重启命令,利用键盘控制器
xor cx,cx
cmd_wait:
in al,64h
test al,2
jz cmd_send
loop cmd_wait
jmp cmd_error
cmd_send:
mov al,bl
out 64h,al
xor cx,cx
cmd_accept:
in al,64h
test al,2
jz cmd_ok
loop cmd_accept
cmd_error:
mov ah,1
jmp cmd_exit
cmd_ok:
xor ah,ah
cmd_exit:
ret
reboot endp
org 8500h
time proc near
mov ah,4h
int 1ah
push cx
lea di,nowtime
mov al,ch
call bcd2asc
pop cx
mov al,cl
call bcd2asc
inc di
mov al,dh
call bcd2asc
inc di
mov al,dl
call bcd2asc
mov ah,2h
int 1ah
push cx
inc di
mov al,ch
call bcd2asc
inc di
pop cx
mov al,cl
call bcd2asc
inc di
mov al,dh
call bcd2asc
call getgb
mov ax,1301h
mov bx,07h
mov cx,19
lea bp,nowtime ;时间地址
int 10h
call scroll
ret
nowtime db 4 dup(?)
db '\'
db 2 dup(?)
db '\'
db 2 dup(?)
db ' '
db ' ',':',' ',':',' '
time endp
bcd2asc proc near
mov bl,al
mov cl,4
shr al,cl
or al,30h
mov [di],al
inc di
mov al,bl
and al,0fh
or al,30h
mov [di],al
inc di
ret
bcd2asc endp
org 85feh
db 55h,0aah
code_seg ends
;-------------------------------------------------------
end start
--------------------------------------------------------------------------------
完,Thx
ASPImage组件的实现过程
作者:sillyboy
下载本文示例源代码
在阅读这篇文章之前,最好能够接触过以下几项
以下是实现过程
一、首先使用Visual C++的向导建立ATL项目

二、接下来添加一个ATL Active Server Page 组件接口类

三、生成名称为AspPicCom的类并且选择ASP内部对象Response

四、在IAspPicCom接口上添加属性和方法,如下表
| 名称 | 类别 | 含义 | 调用方法 |
| FontName | 属性 | 字体名称 | 字符串类型 使用方法 .FontName="宋体" |
| FontSize | 属性 | 字体大小 | 整型 使用方法 .FontSize=40 |
| FontStyle | 属性 | 字体类型 | 整形 Regular = 0, Bold = 1, Italic = 2, BoldItalic = 3, Underline = 4, Strikeout = 8 使用方法 .FontStyle=8 |
| ImgFormat | 属性 | 图形格式 | 字符串类型 image/gif image/jpeg image/bmp ...... 使用方法 .ImgFormat="image/gif" |
| SetFontColor | 方法 | 设置字体颜色 | 使用方法 .SetFontColor 255,3,242,4 上面的数字分别代表Alpha,Red,Green,Blue |
| SetBackColor | 方法 | 设置字体背景颜色 | 使用方法 .SetBackColor 255,3,242,4 上面的数字分别代表Alpha,Red,Green,Blue |
| ShowPic | 方法 | 将图片发送到客户端 | 使用方法 .ShowPic |
#include <Gdiplus.h> using namespace Gdiplus;而且需要连接GDIPlus.lib库
#pragma comment(lib,"gdiplus.lib")2、声明ULONG_PTR gdiplusToken;为一个全局或者类的内部成员变量。
GdiplusStartupInput gdiplusStartupInput; //初始化 GDI+ GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);4、在FinalRelease函数中加入:
GdiplusShutdown(gdiplusToken);这样你就可以使用GDI+提供的图形处理函数了。
注:关于GDI+的使用你可以在以下网址找到参考
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdicpp/gdi+/gdi+.asp
http://www.codeproject.com/vcpp/gdiplus/
六 接下来就是实现在四中列出的这些属性和方法,具体代码请下载我的实例代码
下面列出ShowPic方法的一段代码,其他代码请查看源代码
Bitmap bitmap(1,1,PixelFormat48bppRGB);
Graphics graphics(&bitmap);
USES_CONVERSION;
Font font( OLE2CW(m_bstrFontName),(float)m_fFontSize,m_nFontStyle,UnitPoint,NULL);
PointF origin(0, 0);
StringFormat format;
format.SetAlignment(StringAlignmentCenter);
RectF boundRect;
graphics.MeasureString(OLE2CW(m_bstrText),m_bstrText.Length (), &font, origin, &format, &boundRect);
int nWidth = (int)boundRect.Width;
int nHeight = (int)boundRect.Height;
Bitmap bm(nWidth,nHeight,PixelFormat48bppRGB);
Graphics* g=Graphics::FromImage (&bm);
boundRect.Width=boundRect.Width*2;
SolidBrush solidbrush(m_cBackground);
g->FillRectangle(&solidbrush,boundRect);
SolidBrush SolidFont(m_cFontColor);
PointF fPoint(0,0);
g->DrawString(OLE2CW(m_bstrText),m_bstrText.Length (), &font,fPoint,&SolidFont);
int result;
CLSID pngClsid;
result = GetCodecClsid(OLE2W(m_btrImgFormat ), &pngClsid);
HRESULT hr;
HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE, 0);
CComPtr<IStream> pStm;
if (FAILED(hr = CreateStreamOnHGlobal(hGlobal, TRUE, &pStm) )) return hr;
bm.Save(pStm,&pngClsid,NULL);
ULONG cElements = (ULONG)GlobalSize(hGlobal);
LPBYTE lpData = (LPBYTE)GlobalLock(hGlobal);
SAFEARRAY* pArray = SafeArrayCreateVector(VT_UI1, 0, cElements);
for (UINT iElement = 0; iElement < cElements; iElement++)
{
long idx = iElement;
SafeArrayPutElement(pArray, &idx, ((LPBYTE)lpData) + iElement);
}
GlobalUnlock(hGlobal);
CComVariant vBytes;
vBytes.vt = VT_ARRAY | VT_UI1;
vBytes.parray = pArray;
m_piResponse->Clear ();
m_piResponse->put_ContentType (m_btrImgFormat);
m_piResponse->BinaryWrite(vBytes);
m_piResponse->End ();
七、现在组件的实现部分就大功告成了,我们写一段ASP来测试以下这个组件<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<html>
<body>
<%
set Picture=Server.CreateObject("AspPic.AspPicCom")
picture.Text ="你能看见我吗?我来自www.goodassister.com!"
picture.FontName="黑体"
picture.FontSize= 40
picture.ImgFormat = "image/jpeg"
picture.FontStyle= 1
Picture.SetFontColor 255,3,242,4 ''代表Alpha ,Red,Green,Blue
Picture.SetBackColor 10,243,42,54 ''代表Alpha ,Red,Green,Blue
Picture.ShowPic
set Picture=nothing
%>
</body>
</html>注:在使用前先注册组件 regsvr32 AspPic.dll

题外话:这类组件的用途很广,如yahoo.com注册会员时会显示图形单词以防止计算机自动注册,因为计算机要识别图片上的文字是低效而且很不容易的事情,这类组件更多的是应用到图表的生成,如柱状图、馅饼图、波形图等等。
这篇文章就写到这里了,如果你觉得有什么意见或者我讲错了的地方,请你告诉我
Email:sillyboy@china.com
Thx
(我希望这是一篇教程,而不是一个软件)
初学图形识别,写了个联众台球瞄准辅助程序,玩了几个晚上就成了硬木杆!
2005-8-23
0 鼠标右键点击台球桌面,通过鼠标确定窗口Hwnd,再截图
1 通过截图识别母球位置
2 识别所有分值球的位置
3 鼠标移动时,找到第一个碰到的目标球
4 找出碰撞时母球的球心
5 用第4点找到的母球碰撞坐标与目标球心确定直线方程
6 用第5点确定的方程从目标球球心画出射线
2005-8-18
7 递归化出球得走位
整个过程就是这样,现在这个程序准确率100%,不过算法还需要优化,因为整个识别过程平均要用到2秒,我总觉得很不爽,有时间再优化一下算法,不过用C#写肯定要比C++慢
有兴趣的朋友希望一起来优化算法,代码写的比较烂,下载地址:
/Files/csharphack/lianzhongtaiqiu.rar
压缩包里面的目录说明:
新台球作弊器----------- 界面代码
新台球作弊测试-------- 使用抓图测试核心的工具
MyAnalyze---------------- 核心算法代码