⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 protogen.bat

📁 这是asm驱动的开发包
💻 BAT
📖 第 1 页 / 共 5 页
字号:
;@echo off
;goto make

echo
	echo -----------------
IFDEF DEBUG
	echo | DEBUG Build   |
ELSE
	echo | RELEASE Build |
ENDIF
	echo -----------------
echo

.486
.model flat, stdcall
option casemap:none

;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
;                                  I N C L U D E   F I L E S                                        
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

include \masm32\include\windows.inc

include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
;include \masm32\include\masm32.inc
include clash\clash.inc

includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
;includelib \masm32\lib\masm32.lib
includelib clash\clash.lib

include \masm32\Macros\Strings.mac

include Macros.mac
include seh.inc
include string.asm
include atodw.asm
include memory.asm

;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
;             G L O B A L   V A R I A B L E S   F O R   D E B U G   P U R P O S E S                 
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

;GENERATE_INVOKE		equ 1

;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
;                         F U N C T I O N S   P R O T O T Y P E S                                   
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

strcmp proto C :LPSTR, :LPSTR
externdef strcmp:proc

;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
;                                          M A C R O S                                              
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
		
CC MACRO cc:REQ
	IFNDEF CC_CUR
		CC_CUR = -1		; initialize counter
	ENDIF
	CC_CUR = CC_CUR + 1
	cc equ CC_CUR
ENDM

NewLine MACRO p:REQ
	IF (OPATTR (p)) AND 00010000y
		;; Is a register value
		mov word ptr [p], 0A0Dh
		add p, 2
	ELSE
		mov eax, p
		mov word ptr [eax], 0A0Dh
		add p, 2
	ENDIF
ENDM

il_strlen MACRO s:REQ
	;; fast inline strlen
	IF (OPATTR (s)) AND 00010000y
		;; Is a register value
		IFDIFI <s>, <ecx>
			mov ecx, s
		ENDIF
	ELSE
		mov ecx, s
	ENDIF

	xor	eax, eax
@@:	mov	dl, [ecx+eax]
	inc	eax
	or	dl, dl
	jnz	short @B
	dec	eax

ENDM

;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
;                                         E Q U A T E S                                             
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

MAX_NUM_OF_PARAMS	equ 256

PAGE_SIZE		equ 1000h
PAGE_SHIFT		equ 12

;:::::::::: Define Calling Conventions ::::::::::
CC CC_CDECL
CC CC_STDCALL
;CC CC_ANSI
;CC CC_UNICODE
CC CC_FASTCALL
;CC CC_VARIABLE		; it's not s calling convention of course
;CC CC_PASCAL
;CC CC_THISCALL
;CC CC_NAKED
IFDEF DEBUG
CC CC_WEIRD
ENDIF

CC_NUM		= CC_CUR + 1	; The number of calling conventions types we are goinng to track


IMPORT_CODE				equ 0	; The import is executable code.
IMPORT_DATA				equ	1	; The import is data.
IMPORT_CONST			equ 2	; The import was specified as CONST in the .def file.

IMPORT_ORDINAL			equ 0	; The import is by ordinal. This indicates that the value in the Ordinal/Hint field of the Import Header is the import's ordinal. If this constant is not specified, then the Ordinal/Hint field should always be interpreted as the import's hint.
IMPORT_NAME				equ 1	; The import name is identical to the public symbol name.
IMPORT_NAME_NOPREFIX	equ 2	; The import name is the public symbol name, but skipping the leading ?, @, or optionally _.
IMPORT_NAME_UNDECORATE	equ 3	; The import name is the public symbol name, but skipping the leading ?, @, or optionally _, and truncating at the first @.


;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
;                                    S T R U C T U R E S                                            
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

comment ^
SYM_FLAGS_AND_INDEX RECORD \
	symANSI:1,			; 31 - symbol has 'W' at the very end of its name
	symUNIC:1,			; 30 - symbol has 'A' at the very end of its name
	symCDecl:1,			; 29
	symStdCall:1,		; 28
	symFastCall:1,		; 27
	symPaskal:1,		; 26
	symThisCall:1,		; 25
	symNaked:1,			; 24
	symWeird:1,			; 23
	symVariable:1,		; 22
	sym_Imp:1,			; 21 - symbol has prepending '__imp_'
	symReserved:1,		; 20
	symIndex:20			; 0-19 - hope 20 bits (1048575) is enough for index
						; very big chances that libraries never will grow that big

;   31  30  29  28  27  26  25  24  23  22  21  20  19                                           0  
; +---+---+---+---+---+---+---+---+---+---+---+---+------------------------------------------------+
; | A | W | C | S | F | P | T | N | R | V | I | - | Index - of symbol in the library               |
; +---+---+---+---+---+---+---+---+---+---+---+---+------------------------------------------------+

SYM_ENTRY STRUCT
	pSymbolName			LPSTR				?		; VA to symbol name.

	; if we will need more place for flags it's possible to use 4 most significant bits of this field
	; but then we must work with RVA (from start of library file)
	; i guess it's hard to find the library of size 268'435'455 bytes. So 28 bits for RVA should be enough
	; if we decide to work this way it must be consider in the sorce code of course

	union
		dwFlagsAndIndex	DWORD				?
						SYM_FLAGS_AND_INDEX	<>
	ends
SYM_ENTRY ENDS
^

comment ^
SYM_FLAGS_AND_INDEX RECORD \
	symANSI:1,			; 31 - symbol has 'W' at the very end of its name
	symUNIC:1,			; 30 - symbol has 'A' at the very end of its name
	sym__imp_:1,		; 29 - symbol has prepending '__imp_'
	symReserved:9,		; 20-28
	symIndex:20			; 0-19 - hope 20 bits (1048575) is enough for index
						; very big chances that libraries never will grow that big

;   31  30  29  28  27  26  25  24  23  22  21  20  19                                           0  
; +---+---+---+---+---+---+---+---+---+---+---+---+------------------------------------------------+
; | A | W | I | - | - | - | - | - | - | - | - | - | Index - of symbol in the library               |
; +---+---+---+---+---+---+---+---+---+---+---+---+------------------------------------------------+

SYM_ENTRY STRUCT
	pSymbolName			LPSTR				?		; VA to symbol name.

	; if we will need more place for flags it's possible to use 4 most significant bits of this field
	; but then we must work with RVA (from start of library file)
	; i guess it's hard to find the library of size 268'435'455 bytes. So 28 bits for RVA should be enough
	; if we decide to work this way it must be consider in the sorce code of course

	union
		dwFlagsAndIndex	DWORD				?
						SYM_FLAGS_AND_INDEX	<>
	ends
SYM_ENTRY ENDS
PSYM_ENTRY typedef PTR SYM_ENTRY

^
comment ^
SYM_FLAGS_AND_INDEX RECORD \
	symANSI:1,			; 31 - symbol has 'A' at the very end of its name
	symUNIC:1,			; 30 - symbol has 'W' at the very end of its name
	sym__imp_:1,		; 29 - symbol has prepending '__imp_'
	symReserved:9,		; 20-28
	symIndex:20			; 0-19 - hope 20 bits (1048575) is enough for index
						; very big chances that libraries never will grow that big

;   31  30  29  28  27  26  25  24  23  22  21  20  19                                           0  
; +---+---+---+---+---+---+---+---+---+---+---+---+------------------------------------------------+
; | A | W | I | - | - | - | - | - | - | - | - | - | Index - of symbol in the library               |
; +---+---+---+---+---+---+---+---+---+---+---+---+------------------------------------------------+

SYM_ENTRY STRUCT
	pSymbolName			LPSTR				?		; VA to symbol name.

	; if we will need more place for flags it's possible to use 4 most significant bits of this field
	; but then we must work with RVA (from start of library file)
	; i guess it's hard to find the library of size 268'435'455 bytes. So 28 bits for RVA should be enough
	; if we decide to work this way it must be consider in the sorce code of course

	union
		dwFlagsAndIndex	DWORD				?
						SYM_FLAGS_AND_INDEX	<>
	ends
SYM_ENTRY ENDS
PSYM_ENTRY typedef PTR SYM_ENTRY
^

FF_SYM_ANSI					equ 00000001			; symbol has 'A' at the very end of its name
FF_SYM_UNICODE				equ 00000002			; symbol has 'W' at the very end of its name
FF_SYM___IMP_				equ 00000004			; symbol has prepending '__imp_'
FF_SYM_VARIABLE				equ 00000008			; symbol is possibly a variable not a function



SYM_ENTRY STRUCT
													;       _StrFormatByteSize64A@16
													; __imp__DdeCmpStringHandles@8
													;       ^
													;       |
													;       +------------+
													;                    |
	pSymbolName					LPSTR		?		; VA to symbol name -+

													; _StrFormatByteSize64A@16
													;  ^
													;  |
													;  +----------------------------------------------+
													;                                                 |
	pUndecSymbolNameStart		LPSTR		?		; VA to the beginning of undecorated symbol name -+

													; _StrFormatByteSize64A@16
													;  \________  ________/
													;           \/
	ccUndecSymbolNameLength		UINT		?		; num of chars of undecorated symbol name.

	uNumberOfParameters			UINT		?		; Number of accepting by function parameters or -1 if not recognized
													; For _StrFormatByteSize64A@16 uNumberOfParameters = 16/4 = 4

	uIndex						UINT		?		; Index of symbol in the library

	pMemberHeader				LPSTR		?		; VA to symbol's IMAGE_ARCHIVE_MEMBER_HEADER

	dwFlags						DWORD		?		; FF_SYM_XXX

	byImportType				BYTE		?		; IMPORT_CODE, IMPORT_DATA, IMPORT_CONST
	byImportNameType			BYTE		?		; IMPORT_ORDINAL, IMPORT_NAME, IMPORT_NAME_NOPREFIX, IMPORT_NAME_UNDECORATE
	
	wReserved					WORD		?

SYM_ENTRY ENDS
PSYM_ENTRY typedef PTR SYM_ENTRY


CC_ENTRY STRUCT
	uNumEntries	UINT		?		; Number of the SYM_ENTRY in the array
	pSymEntries	PSYM_ENTRY	?		; Points to the beginning of the SYM_ENTRYs array of appropriate CC
CC_ENTRY ENDS
PCC_ENTRY typedef PTR CC_ENTRY



UNDECOR_SYMBOL STRUCT
	; Dont' change this structure
	pUndecName		LPSTR	?
	uUndecLenght	UINT	?
UNDECOR_SYMBOL ENDS
PUNDECOR_SYMBOL typedef PTR UNDECOR_SYMBOL

;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
;                                     C O N S T A N T S                                             
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

.const
CTA0 ".lib", g_szLibExtension, 4

CTA0 "v1.0", g_szVersion, 4

IFDEF DEBUG
	CTA0 "\nWarning: %s\n\n", g_szDbgWeirdSymbol, 4
;	CTA0 "\nWarning: Too many params %s\n", g_szWeirdNumOfParams, 4
	CTA0 "\nWarning: Corresponding unicode symbol for %s was not found\n\n", g_szDbgUnicSymbolNotFound, 4
ENDIF

CTA0 "\nWarning: argument count of %s is not devisible by 4.\n\n", g_szArgCountNotDivBy4, 4

CTA ";:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::\n", g_szCommentedLine, 4
CTA "\t", g_szTab, 4
CTA " equ \[", g_szEqu, 4
;CTA "\n", g_szNewLine
CTA "IFDEF UNICODE\n", g_szIfDefUnicode, 4
CTA "ELSE\n", g_szElseUnicode, 4
CTA "ENDIF\n", g_szEndIfUnicode, 4
CTA "\t; possible exported variable", g_szExportedVariable, 4
CTA0 "__imp_", g_sz__imp_, 4

IFDEF GENERATE_INVOKE
CTA "invoke ", g_szInvoke, 4
CTA ", 0", g_szZero, 4
ENDIF

;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
;                              I N I T I A L I Z E D  D A T A                                       
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

.data

;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
;                              U N I N I T I A L I Z E D  D A T A                                   
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

.data?
;g_hConsoleInput		HANDLE ?
PUBLIC g_hConsoleOutput
g_hConsoleOutput	HANDLE	?
g_pszCommandLine	LPVOID	?

g_hLibraryFile		HANDLE	?
g_hLibraryMapping	HANDLE	?
g_pLibraryImage		LPVOID	?

;g_hIncludeFile		HANDLE	?
;g_hIncludeMapping	HANDLE	?
g_pInclude			LPVOID	?
g_cbInclude			UINT	?
g_pIncludeCurrent	LPVOID	?


g_pSymEntries		LPVOID	?
g_cbSymEntries		UINT	?



g_uNumberOfMembers	UINT	?	; Unsigned long containing the number of archive members.
g_uNumberOfSymbols	UINT	?	; Unsigned long containing the number of symbols indexed.
								; Each object-file member typically defines one or more external symbols.


g_uNumOfVariables	UINT	?


align 4
; Array of CC_ENTRYs. Each CC_ENTRY correspond to particular calling convention type we are tracking
g_paCcEntries		db (sizeof CC_ENTRY) * CC_NUM dup(?)

;g_apPointers		db (sizeof CC_ENTRY) * CC_NUM dup(?)

align 4
g_acLibraryPath		CHAR MAX_PATH	dup(?)

IFDEF DEBUG
	g_acDebugMessage	CHAR 256 dup(?)
ENDIF

g_fSortUndecorated	DWORD	?

; Command line switches
; 'm' masm, 'f' fasm, 't' tasm, 'n' nasm
g_keyIncludeType	CHAR	?
g_keySort			CHAR	?
g_keyDirectImport	BYTE	?	; suppress jump table
;g_keyNoLogo			BYTE	?	; suppress logo printing

;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
;                                       C O D E                                                     
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

.code

;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
;                                       PrintConsole                                                
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

PrintConsole proc psz:LPSTR, dwAttributes:DWORD

local csbi:CONSOLE_SCREEN_BUFFER_INFO
local dwNumberOfBytesWritten:DWORD

	.if dwAttributes != 0
		invoke GetConsoleScreenBufferInfo, g_hConsoleOutput, addr csbi
		invoke SetConsoleTextAttribute, g_hConsoleOutput, dwAttributes
	.endif

	.if psz != NULL
		invoke fstrlen, psz
		.if eax
			mov ecx, eax
			invoke WriteFile, g_hConsoleOutput, psz, ecx, addr dwNumberOfBytesWritten, NULL
		.endif
	.endif

	.if dwAttributes != 0
		movzx eax, csbi.wAttributes
		invoke SetConsoleTextAttribute, g_hConsoleOutput, eax
	.endif

	ret

PrintConsole endp

;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
;                                IsLibExtensionSpecified                                            
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -