📄 api.asm
字号:
.386P
_apiCode segment para 'API CODE' use32
assume cs:_apiCode, ds:_apiCode
_apiCodeStart label byte
;-------------------------------------------------------------------------
;
apiSystemFlags dw 0,0
DescriptorBuffer db 8 dup (?)
apiDSeg dw ?
apiDDSeg dw ?
;
apiNewHeader NewHeaderStruc <> ;make space for a header.
;
apiExeSignature db ? ;00 Identifier text.
db ? ;01 /
apiExeLength dw ? ;02 Length of file MOD 512
dw ? ;04 Length of file in 512 byte blocks.
apiExeRelocNum dw ? ;06 Number of relocation items.
apiExeHeaderSize dw ? ;08 Length of header in 16 byte paragraphs.
apiExeMinAlloc dw ? ;0A Minimum number of para's needed above program.
apiExeMaxAlloc dw ? ;0C Maximum number of para's needed above program.
apiExeStackSeg dw ? ;0E Segment displacement of stack module.
apiExeEntrySP dw ? ;10 value for SP at entry.
apiExeCheckSum dw ? ;12 Check sum...
apiExeEntryIP dw ? ;14 Contents of IP at entry.
apiExeEntryCS dw ? ;16 Segment displacement of CS at entry.
apiExeRelocFirst dw ? ;18 First relocation item offset.
apiExeOverlayNum db ? ;1A Overlay number.
;
LastResource dd 0,0
;
PatchTable dd 16 dup (0)
mcbLastChunk dd 0
ExecMCount dd 0
;*******************************************************************************
;Put carry into return carry.
;*******************************************************************************
cwAPI_C2C macro
push eax
pushfd
pushfd
pop eax
and al,1
cwAPI_AL2C
popfd
pop eax
endm
;*******************************************************************************
;Put carry into return carry.
;*******************************************************************************
cwAPI_AL2C macro
local __0, __1
pushfd
assume ds:nothing
test BYTE PTR cs:apiSystemFlags,1
jz __0
or b[ebp+Int_Flags16],al
jmp __1
__0: or b[ebp+Int_Flags32],al
__1: assume ds:_apiCode
popfd
endm
;*******************************************************************************
;Call old int 31h handler.
;*******************************************************************************
cwAPI_CallOld macro
local __0, __1
assume ds:nothing
test BYTE PTR cs:apiSystemFlags,1
jz __0
pushf
db 66h
call FWORD PTR cs:[OldIntSys] ;pass it onto previous handler.
jmp __1
__0: pushfd
call FWORD PTR cs:[OldIntSys] ;pass it onto previous handler.
__1: assume ds:_apiCode
endm
;*******************************************************************************
;Convert character in AL to upper case.
;*******************************************************************************
UpperChar macro
local __0
cmp al,61h ; 'a'
jb __0
cmp al,7Ah ; 'z'
ja __0
and al,5Fh ;convert to upper case.
__0: ;
endm
;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
;
;This must be just before cwAPIpatch
;
cwIdentity db "CAUSEWAY"
cwMajorVersion db 0
cwMinorVersion db 0
;
;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
;
;CW API int 31h patch.
;
cwAPIpatch proc near
push ds
push es
push fs
push gs
pushad ;/
mov ebp,esp ;Make registers addressable.
;
;Check if we're allowed to interfere.
;
push ds
assume ds:nothing
mov ds,cs:apiDSeg
assume ds:_cwMain
cmp Int21hExecCount,0
assume ds:_apiCode
pop ds
jnz api1_Nope
;
;Check if this is a CauseWay function.
;
cmp ah,255
jz api1_Ours
;
;Scan the table of other relavent functions.
;
mov edi,offset apiExtraCallTable+2
api1_extra: cmp WORD PTR cs:[edi-2],0
jz api1_Nope
cmp ax,WORD PTR cs:[edi-2]
jz api1_GotCall
add edi,4+2
jmp api1_extra
;
;An internal funtion? so point to table entry.
;
api1_Ours: movzx edi,al
shl edi,2
add edi,offset apiCallTable
;
;Check if final call is still going to pass control to the old handler.
;
api1_GotCall: cmp DWORD PTR cs:[edi],0
jz api1_Nope
;
;See about turning interrupts back on.
;
mov esi,Int_Flags32
assume ds:nothing
test BYTE PTR cs:apiSystemFlags,1 ;/
assume ds:_apiCode
jz api1_32bit0 ;/
movzx ebp,bp ;/
mov esi,Int_Flags16
api1_32Bit0: and BYTE PTR ss:[ebp+esi],not 1 ;clear carry.
cld ;Default direction.
test WORD PTR ss:[ebp+esi],1 shl 9 ;Were interrupts enabled?
jz api1_NoInts
sti ;Turn interrupts back on.
;
;Call the function handler.
;
api1_NoInts: assume ds:nothing
call DWORD PTR cs:[edi] ;Pass control to handler.
assume ds:_apiCode
popad ;\
pop gs
pop fs
pop es
pop ds
assume ds:nothing
test BYTE PTR cs:apiSystemFlags,1
assume ds:_apiCode
jz api1_32Bit1
iret
api1_32Bit1: iretd ;Return to caller.
;
;Not an internal function or anything we want to interfere with so pass control
;to origional handler.
;
api1_Nope: popad ;Restore registers.
pop gs
pop fs
pop es
pop ds
assume ds:nothing
test BYTE PTR cs:apiSystemFlags,1
jz api1_n32
db 66h
api1_n32: jmp FWORD PTR cs:[OldIntSys] ;pass it onto previous handler.
assume ds:_apiCode
;
OldIntSys df 0
;
APICallTable dd cwAPI_Info ;00
dd cwAPI_IntXX ;01
dd cwAPI_FarCallReal ;02
dd cwAPI_GetSel ;03
dd cwAPI_RelSel ;04
dd cwAPI_CodeSel ;05
dd cwAPI_AliasSel ;06
dd cwAPI_GetSelDet ;07
;
dd cwAPI_GetSelDet32 ;08
dd cwAPI_SetSelDet ;09
dd cwAPI_SetSelDet32 ;0A
dd cwAPI_GetMem ;0B
dd cwAPI_GetMem32 ;0C
dd cwAPI_ResMem ;0D
dd cwAPI_ResMem32 ;0E
dd cwAPI_RelMem ;0F
;
dd cwAPI_GetMemLinear ;10
dd cwAPI_GetMemLinear32 ;11
dd cwAPI_ResMemLinear ;12
dd cwAPI_ResMemLinear32 ;13
dd cwAPI_RelMemLinear ;14
dd cwAPI_RelMemLinear32 ;15
dd cwAPI_GetMemNear ;16
dd cwAPI_ResMemNear ;17
;
dd cwAPI_RelMemNear ;18
dd cwAPI_Linear2Near ;19
dd cwAPI_Near2Linear ;1A
dd cwAPI_LockMem ;1B
dd cwAPI_LockMem32 ;1C
dd cwAPI_UnLockMem ;1D
dd cwAPI_UnLockMem32 ;1E
dd cwAPI_LockMemNear ;1F
;
dd cwAPI_UnLockMemNear ;20
dd cwAPI_GetMemDOS ;21
dd cwAPI_ResMemDOS ;22
dd cwAPI_RelMemDOS ;23
dd cwAPI_Exec ;24
dd cwAPI_GetDOSTrans ;25
dd cwAPI_SetDOSTrans ;26
dd cwAPI_GetMCBSize ;27
;
dd cwAPI_SetMCBSize ;28
dd cwAPI_GetSels ;29
dd cwAPI_cwLoad ;2A
dd cwAPI_cwcInfo ;2B
dd cwAPI_GetMemSO ;2C
dd cwAPI_ResMemSO ;2D
dd cwAPI_RelMemSO ;2E
dd cwAPI_UserDump ;2F
; dd 16 dup (0) ;30-3F
dd cwAPI_SetDump ; 30
dd cwAPI_UserErrTerm ; 31
dd cwAPI_CWErrName ; 32
dd 13 dup (0) ;33-3F
dd 16 dup (0) ;40-4F
dd 16 dup (0) ;50-5F
dd 16 dup (0) ;60-6F
dd 16 dup (0) ;70-7F
;
dd 16*7 dup (0) ;80-EF
;
dd 8 dup (0) ;F0-F7
;
dd 0 ;F8
dd cwAPI_ID ;F9
dd cwAPI_GetPatch ;FA
dd cwAPI_cwcLoad ;FB
dd cwAPI_LinearCheck ;FC
dd cwAPI_ExecDebug ;FD
dd cwAPI_Cleanup ;FE
dd 0 ;FF
;
apiExtraCallTable label byte
dw 0600h
dd dpmiAPI_Lock
dw 0601h
dd dpmiAPI_UnLock
dw 0303h
dd dpmiAPI_GetCallBack
dw 0304h
dd dpmiAPI_RelCallBack
dw 0
cwAPIpatch endp
;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
;
;AX = 0600h
;BX:CX = Starting linear address of memory to lock
;SI:DI = Size of region to lock in bytes
;
dpmiAPI_Lock proc near
mov ax,[ebp+Int_AX]
mov bx,[ebp+Int_BX]
mov cx,[ebp+Int_CX]
mov si,[ebp+Int_SI]
mov di,[ebp+Int_DI]
pushad
shl ebx,16
mov bx,cx
shl esi,16
mov si,di
mov edx,ebx
mov ecx,esi
mov ax,Res_LOCK
call RegisterResource
popad
cwAPI_CallOld
cwAPI_C2C
jnc api2_0
mov [ebp+Int_AX],ax
api2_0: ret
dpmiAPI_Lock endp
;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
;
;AX = 0601h
;BX:CX = Starting linear address of memory to unlock
;SI:DI = Size of region to unlock in bytes
;
dpmiAPI_UnLock proc near
mov ax,[ebp+Int_AX]
mov bx,[ebp+Int_BX]
mov cx,[ebp+Int_CX]
mov si,[ebp+Int_SI]
mov di,[ebp+Int_DI]
pushad
shl ebx,16
mov bx,cx
shl esi,16
mov si,di
mov edx,ebx
mov ecx,esi
mov ax,Res_LOCK
call ReleaseResource
popad
cwAPI_CallOld
cwAPI_C2C
jnc api3_0
mov [ebp+Int_AX],ax
api3_0: ret
dpmiAPI_UnLock endp
;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
;
;AX = 0303h
;DS:(E)SI = Selector:Offset of procedure to call
;ES:(E)DI = Selector:Offset of real mode call structure
;
;Returns
;
;If function was successful:
;Carry flag is clear.
;CX:DX = Segment:Offset of real mode call address
;
dpmiAPI_GetCallBack proc near
mov ax,[ebp+Int_AX]
mov ds,[ebp+Int_DS]
mov esi,[ebp+Int_ESI]
mov es,[ebp+Int_ES]
mov edi,[ebp+Int_EDI]
cwAPI_CallOld
cwAPI_C2C
jc api4_9
;
mov [ebp+Int_CX],cx
mov [ebp+Int_DX],dx
;
shl ecx,16
mov cx,dx
mov edx,ecx
mov ecx,esi
xor ebx,ebx
mov bx,ds
mov ax,Res_CALLBACK
call RegisterResource
;
api4_9: ret
dpmiAPI_GetCallBack endp
;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
;
;AX = 0304h
;CX:DX = Real mode call-back address to free
;
dpmiAPI_RelCallBack proc near
mov ax,[ebp+Int_AX]
mov cx,[ebp+Int_CX]
mov dx,[ebp+Int_DX]
cwAPI_CallOld
cwAPI_C2C
jc api5_9
;
shl ecx,16
mov cx,dx
mov edx,ecx
mov ax,Res_CALLBACK
call ReleaseResource
;
api5_9: ret
dpmiAPI_RelCallBack endp
;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
;
;Call user^Aermination routine on exception
;
;On Entry:
;
; AX = 0ff31h
; CL = 0 if 16-bit termination routine
; CL = nonzero if 32-bit termination routine
; DS:[E]SI = user termination routine address, if ES is zero or an invalid
; selector value, then the user termination routine call is removed
; ES:[E]DI = user information dump area
;
;Returns:
;
; None
;
cwAPI_UserErrTerm PROC NEAR
mov ds,cs:apiDSeg
assume ds:_cwMain
mov UserTermFlag,0 ; initialize flag
mov dx,[ebp+Int_DS]
lsl ax,dx
jnz uetret ; invalid selector
mov al,[ebp+Int_CL] ; get bitness flag
test al,al
setne al ; 0 if 0, 1 if nonzero
inc ax ; 1 if 16-bit, 2 if 32-bit
mov UserTermFlag,al
cmp al,1 ; see if 16-bit
jne uet32 ; no
mov ax,[ebp+Int_SI]
mov WORD PTR UserTermRoutine,ax
mov WORD PTR UserTermRoutine+2,dx
mov ax,[ebp+Int_DI]
mov WORD PTR UserTermDump,ax
mov ax,[ebp+Int_ES]
mov WORD PTR UserTermDump+2,ax
jmp uetret
uet32:
mov eax,[ebp+Int_ESI]
mov DWORD PTR UserTermRoutine,eax
mov WORD PTR UserTermRoutine+4,dx
mov eax,[ebp+Int_EDI]
mov DWORD PTR UserTermDump,eax
mov ax,[ebp+Int_ES]
mov WORD PTR UserTermDump+4,ax
uetret:
ret
cwAPI_UserErrTerm ENDP
;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
;
;Disable/enable error display and CW.ERR creation
;
;On Entry:
;
; AX = 0ff30h
; CL = 0, disable error display and CW.ERR file creation
; CL = nonzero, enable error display and CW.ERR file creation
;
;Returns:
;
; None
;
cwAPI_SetDump PROC NEAR
mov ds,cs:apiDSeg
assume ds:_cwMain
mov al,[ebp+Int_CL]
mov EnableDebugDump,al
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -