汇编界没人啊,一个小小的加密程序都无人应答!!

OldBoy 2000-06-16 12:19:00
这是一个加密的东东,有段程序我没看懂,不知道[si+1ah]和[si+18h]有什么特殊用处,分别放入了什么?0630h是什么?
这段程序在标号transfer: 下边的地方.

";修改程序头部,使程序的入口点处(100h处)的代码为com_head
mov cx,20h
lea si,com_head
lea di,buffer
mov [si+1ah],ax
mov [si+18h],0630h
rep movsb
"

--------------------------------------------------------------------------------

下面是源代码:
code segment
assume cs:code,ds:code
org 100h

;以下是插入到目标程序中的代码,用途是:检查用户口令,解密,返回到程序原入口点
addprog proc far
mov ax,cs
mov ds,ax
mov psp,es
mov es,ax

mov save_ss,ss
mov save_sp,sp
mov sp,cs
mov ss,sp
mov sp,offset stack_ptr

mov ax,psp
add souc_seg,ax
add souc_seg,10h

mov cx,6
input: mov ah,9
lea dx,dirmsg
int 21h

push cx
mov cx,32
lea di,password
get_input:
mov ah,8
int 21h
stosb
cmp al,0dh
jz compare
mov ah,2
mov dl,42
int 21h
loop get_input

compare: pop cx
mov dl,0dh
mov ah,2
int 21h

lea si,password
add si,4
mov di,si
load: lodsb
not al
stosb
cmp al,0ffh
jz on_comp
cmp al,0f2h
jnz load

on_comp: lea si,keyword
lea di,password
add di,4

comp: cmpsb
jnz wr_input
dec si
lodsb
cmp al,0f2h
jz end_comp
jmp comp
;口令非法,提示错误后重新输入
wr_input: mov ah,9
lea dx,wrong
int 21h
loop input
jmp cs:reset
;口令合法
end_comp: lea dx,right
mov ah,9
int 21h
;跳回到程序原来的入口点
chain_back: cmp byte ptr isexe,0
je com_back
;这段是.exe程序用的,用密码修正地址后返回
lea bx,password
mov ax,[bx]
add souc_seg,ax
mov ax,[bx+2]
add souc_off,ax
jmp return
;这段是.com程序用的,把保存在head_save中的原程序32字节解密后拷回到100h处
com_back: lea bx,password
mov ax,psp
mov es,ax
lea si,head_save
mov di,100h
mov cx,10h
loadw: lodsw
xor ax,[bx]
xor ax,[bx+2]
stosw
loop loadw
;返回原程序,通过两个push操作将返回地址指向程序原来的入口代码
return: mov sp,save_sp
push cs:souc_seg
push cs:souc_off
mov dx,psp
mov es,dx
mov ds,dx
xor si,si
xor di,di
retf

save_ss dw ?
save_sp dw ?
souc_off dw ?
souc_seg dw ?
dirmsg db 09h,09h,'Enter your PASSWORD here ... $'
right db 0dh,0ah,09h,09h,' Program continued ... ',0dh,0ah,'$'
wrong db 0dh,0ah,09h,09h,' Wrong password !',0dh,0ah,'$'
reset label dword
reset_off dw 0fff0h
reset_seg dw 0f000h
psp dw ?
isexe db 0
head_save db 20h dup(0)
pro_stack dw 20h dup(0)
stack_ptr dw 0
keyword db 16 dup(0)
password db 32 dup(0)
buff db 1024 dup (0)
endprog label word

addprog endp

;以下是主程序
main: mov ax,ds
mov cs:psp_seg,ax
push cs
pop es
;以下部分是命令行参数的分析
mov al,byte ptr ds:[80h]
push cs
pop ds
cmp al,0
jz main_help
;得到文件名
call get_name
jnc continue

lea dx,dmsg1
mov ah,9
int 21h

lea dx,keybuf
mov ax,0c0ah ;get keyboard buffer
int 21h
;让用户输入口令
continue: call get_pass
jc main_ret
;打开文件
call find_file
jc main_ret
;修改文件
call add_file
jc main_ret
mov bx,handle
mov ah,3eh
int 21h ;close file

lea dx,msg4
mov ah,9
int 21h
;退出
main_ret: mov ax,4c00h
int 21h ;main program end

main_help: mov ah,9
lea dx,help
int 21h
jmp main_ret


get_name proc near
push ds
mov ax,psp_seg
mov ds,ax
mov si,82h
lea di,filename
mov ds,cs:psp_seg
call parsename
mov al,0
stosb
inc si
mov ch,00
mov cl,byte ptr ds:[80h]
add cx,82h
cmp cx,si
jne get_word
stc
pop ds
ret

get_word: lea di,key_cs
call parsename
mov al,0dh
stosb
pop ds
ret

parsename: cld
m01: cmp byte ptr [si],' '
jne m02
inc si
jmp m01
m02: cmp byte ptr [si],';'
je m03
cmp byte ptr [si],' '
je m03
cmp byte ptr [si],'/'
je m03
cmp byte ptr [si],','
je m03
cmp byte ptr [si],0dh
je m03
cmp byte ptr [si],0ffh
je m03
movsb
jmp m02
m03: ret
get_name endp


get_pass proc near
lea si,chars
lea di,keyword ;get password
get_char: lodsb
not al
stosb
cmp al,0ffh
jz get_ret
cmp al,0f2h
jnz get_char
get_ret: ret
get_pass endp


find_file proc near
lea dx,buffer
mov ah,1ah
int 21h
lea dx,filename
mov ah,4eh
int 21h
jnc openfile1
lea dx,msg1
ferr_ret: mov ah,9
int 21h
stc
ret
openfile1: lea dx,filename
mov al,2
mov ah,3dh
int 21h ;open file for read/write
mov handle,ax
lea dx,msg2
jc ferr_ret
ret
find_file endp


add_file proc near
;读文件头
lea dx,buffer ;read file head
mov bx,handle
mov cx,20h
mov ah,3fh
int 21h
or ax,ax
jz point_err

lea di,buffer
cmp [di],5a4dh ;EXE file
jnz no_exe
;如果是.exe文件
mov isexe,1
;修改文件头中的入口地址
call head_deal
;将修改过的文件写回
write: call to_head ;move pointer to head
call write_head
jc point_err

call to_tail ;move pointer to tail
call write_file
jc point_err
ret

point_err: lea dx,msg2
mov ah,9
int 21h
stc
ret
;如果是.com文件
no_exe: mov isexe,0
;保存程序头部的32字节到head_save,并将其用用户输的口令加密
lea si,buffer
lea di,head_save
mov cx,10h
transfer: lodsw
xor ax,key_ip
xor ax,key_cs
stosw
loop transfer

mov souc_off,100h
mov souc_seg,0fff0h
;修改程序长度
call to_tail
add ax,1fh
and ax,0fff0h
mov cs:file_low,ax
mov cs:file_high,dx

mov cl,4
shr ax,cl
;修改程序头部,使程序的入口点处(100h处)的代码为com_head
mov cx,20h
lea si,com_head
lea di,buffer
mov [si+1ah],ax
mov [si+18h],0630h
rep movsb
;写回
jmp write

com_head: mov dx,cs
;返回到位于文件尾处的addprog
mov ax,cs:[11ah]
add ax,dx
push ax
mov ax,100h
push ax
retf
null db 20h dup(0)

sub_ret: ret

add_file endp

;修改.exe文件的文件头,使其入口点为自己的代码
head_deal proc near
mov ax,[di+14h]
sub ax,key_ip
mov souc_off,ax ;source code offset
mov ax,[di+16h]
sub ax,key_cs
mov souc_seg,ax ;source code segment
;修改文件长度
call to_tail
add ax,1fh
adc dx,0
and ax,0fff0h
mov cs:file_low,ax
mov cs:file_high,dx

mov cx,10h
div cx
sub ax,10h
sub ax,[di+08h]

mov word ptr [di+14h],100h ;new cs offset
mov word ptr [di+16h],ax ;new cs segment

mov ax,cs:file_low
mov dx,cs:file_high
;将入口点指定为addprog
lea cx,endprog
sub cx,100h
add ax,cx
adc dx,0
mov cx,200h
div cx
inc ax

mov [di+2],dx
mov [di+4],ax
ret

head_deal endp

;将文件指针移动到文件尾
to_tail proc near
mov ax,4202h ;move pointer to file tail
mov cx,0
mov dx,0
int 21h
ret
to_tail endp
;将文件指针移动到文件头
to_head proc near
mov ax,4200h ;move pointer to file head
mov cx,0
mov dx,0
int 21h
ret
to_head endp
;写文件头
write_head proc near
mov ah,40h ;write file head
lea dx,buffer
mov cx,20h
int 21h
ret
write_head endp
;把addprog的代码加到文件尾
write_file proc near
mov dx,100h
mov cx,cs:file_low
sub cx,ax
sub dx,cx
mov ax,cx
lea cx,endprog
add cx,ax
sub cx,100h
mov ah,40h
int 21h
ret
write_file endp

help db 'LOCK (R) Version 4.00a Copyright (C) Technique Department 1993-94.'
db 0dh,0ah,'Examples:'
db 0dh,0ah,' LOCK drive:\path\[filename]'
db 0dh,0ah,' LOCK [filename] [password]'
db 24h
dmsg1 db 'Software (R) File Lock Utility (tm) Version 4.00a'
db 0dh,0ah
db 'Copyright (C) Technique Department 1993-94. All rights reserved.'
db 0dh,0ah,0dh,0ah
db 'KEYWORD of source file (at least 5 characters): $'
msg1 db 0dh,0ah,'File can not find.$'
msg2 db 0dh,0ah,'File can not read or disk is full.$'
msg3 db 0dh,0ah,'Not EXE file.$'
msg4 db 0dh,0ah,'File lock successfully.$'
psp_seg dw 0
file_low dw 0
file_high dw 0
keybuf db 32h
umchar db 0
key_cs dw 0
key_ip dw 0
chars db 28h dup(0)
handle dw 0
filename db 16h dup(?)
buffer db 20h dup(?)
buff1 db 1024 dup (0)
code ends
end main
...全文
298 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
OldBoy 2000-06-18
  • 打赏
  • 举报
回复
永别汇编版块,过去的MACH和现在的PCCRAZY,是少有的热心人——尤其与冷清的场面和无能的斑竹相比较起来!
OldBoy 2000-06-17
  • 打赏
  • 举报
回复
那个0630H到底是什么意思?有没有人知道?
pccrazy 2000-06-16
  • 打赏
  • 举报
回复
不要用激将法嘛!

018h EXE文件的重定向表的offset

01ah 是Overlay的大小,也就是在EXE中加入的附加信息(如Debug Info)

茂奇软件 2000-06-16
  • 打赏
  • 举报
回复
我已经注意您的行为恒久了。这样的汇编代码
并没有很多的技巧。我认为您只是希望别人为
你做注解。您在剥削别人的劳动力。(我是这
样认为的。更希望在这里看到i386p和DDK的
问题)

版卒,jansenzhu.
OldBoy 2000-06-16
  • 打赏
  • 举报
回复
不要光说努力的话啊!请赶快帮我一把啊!十万火急!!!!!
茂奇软件 2000-06-16
  • 打赏
  • 举报
回复
大家多努力吧。
OldBoy 2000-06-16
  • 打赏
  • 举报
回复
诸位不要误解我的意思,我的汇编知识实在不行,但这个程序对我又特别重要,所以才想到来CSDN求教。求教是真心的,难道还要分难度大小吗?希望有热心人做详细地讲解。谢谢!
Wonny 2000-06-16
  • 打赏
  • 举报
回复
其实很多书上都有解释的。昨天我也看到了,只是太长,累。

21,453

社区成员

发帖
与我相关
我的任务
社区描述
汇编语言(Assembly Language)是任何一种用于电子计算机、微处理器、微控制器或其他可编程器件的低级语言,亦称为符号语言。
社区管理员
  • 汇编语言
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧