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

📄 protogen.bat

📁 这是asm驱动的开发包
💻 BAT
📖 第 1 页 / 共 5 页
字号:
				add eax, edx

				mov edx, [eax]
				bswap edx				; edx -> IMAGE_ARCHIVE_MEMBER_HEADER
				mov eax, g_pLibraryImage
				add eax, edx
				add eax, sizeof IMAGE_ARCHIVE_MEMBER_HEADER	; eax -> IMPORT_OBJECT_HEADER
				assume eax:ptr IMPORT_OBJECT_HEADER
				mov dx, [eax].rImport
				assume eax:nothing

				and edx, mask Type2
				.if edx == IMPORT_OBJECT_CODE
					; The import is executable code.
					mov dwCcType, CC_CDECL
				.elseif edx == IMPORT_OBJECT_DATA
					; The import is data.
					mov dwCcType, CC_VARIABLE
				.elseif edx == IMPORT_OBJECT_CONST
					; The import was specified as CONST in the .def file.
					mov dwCcType, CC_VARIABLE
				.else
					IFDEF DEBUG
						mov dwCcType, CC_WEIRD
;					ELSE
;						_mov dwCcType, -1	; ???
					ENDIF
				.endif		
^
			.endif

			mov eax, esi
			inc eax
			mov pUndecSymbolNameStart, eax

			mov eax, uAtPosition
			.if [esi][eax][-1] == 'A'		; ANSI or Unicode ?
				or dwSymFlags, FF_SYM_ANSI
			.elseif [esi][eax][-1] == 'W'
				or dwSymFlags, FF_SYM_UNICODE
			.endif
IFDEF DEBUG
		.else
			mov dwCcType, CC_WEIRD
ENDIF
		.endif

		mov eax, dwCcType
		.if eax != -1

			; Fill in SYM_ENTRY for this symbol

			mov ecx, [edi][eax*(sizeof CC_ENTRY)].uNumEntries
			inc [edi][eax*(sizeof CC_ENTRY)].uNumEntries		; num = num + 1
			mov edx, [edi][eax*(sizeof CC_ENTRY)].pSymEntries	; edx -> first SYM_ENTRY of particular cc type

			mov eax, ecx
			imul eax, (sizeof SYM_ENTRY)


			mov (SYM_ENTRY PTR [edx])[eax].pSymbolName, esi

			mov ecx, pUndecSymbolNameStart
			mov (SYM_ENTRY PTR [edx])[eax].pUndecSymbolNameStart, ecx


			mov ecx, dwSymFlags
			mov (SYM_ENTRY PTR [edx])[eax].dwFlags, ecx

			mov ecx, uIndex
			mov (SYM_ENTRY PTR [edx])[eax].uIndex, ecx

			; VA to symbol's IMAGE_ARCHIVE_MEMBER_HEADER
			mov ecx, pMemberHeader
			mov (SYM_ENTRY PTR [edx])[eax].pMemberHeader, ecx


			; num of chars of undecorated symbol name.
			mov ecx, ccUndecSymbolNameLength			
			mov (SYM_ENTRY PTR [edx])[eax].ccUndecSymbolNameLength, ecx


			; Number of accepting by function parameters or -1 if not recognized
			mov ecx, uNumberOfParameters			
			mov (SYM_ENTRY PTR [edx])[eax].uNumberOfParameters, ecx


			; Import Type
			mov cl, byImportType			
			mov (SYM_ENTRY PTR [edx])[eax].byImportType, cl


			; Import Name Type
			mov cl, byImportNameType			
			mov (SYM_ENTRY PTR [edx])[eax].byImportNameType, cl

		.endif
@@:
		invoke fstrlen, esi
		add esi, eax
		inc esi							; skip terminating zero
		inc ebx							; next symbol
	.endw

	inc fOk

	_finally

	assume esi:nothing
	assume edi:nothing

	return fOk

FillSymEntries endp

;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
;                                         strncmp                                                   
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

strncmp proc uses esi edi ps1:LPSTR, ps2:LPSTR, n:UINT

	xor eax, eax
	mov esi, ps1
	mov edi, ps2
	mov ecx, n
	repe cmpsb
	.if !ZERO?
		inc eax
	.endif

	ret

strncmp endp

;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
;                                       PrintSummary                                                
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

PrintSummary proc uses esi

local acSummary[256]:CHAR

;	CL_argv[1*(sizeof DWORD)]

;	Dump of file hello2.obj
;	invoke PrintConsole, addr acSummary

	lea esi, g_paCcEntries
	assume esi:ptr CC_ENTRY
	xor edx, edx
	xor ecx,  ecx
	.while ecx < sizeof g_paCcEntries/sizeof CC_ENTRY
		add edx, [esi][(sizeof CC_ENTRY)*ecx].uNumEntries
		inc ecx
	.endw

	CTA "\n", g_szSummaryFormat, 4
	CTA "cdecl           : %d\n"
	CTA "stdcall         : %d\n"
;	CTA "stdcall neutral : %d\n"
;	CTA "stdcall ansi    : %d\n"
;	CTA "stdcall unicode : %d\n"
	CTA "fastcall        : %d\n"
	CTA "variables       : %d\n"
	CTA "----------------------\n"
	CTA "total           : %d\n\n\0"

	invoke wsprintf, addr acSummary, addr g_szSummaryFormat, \
		[esi][(sizeof CC_ENTRY)*CC_CDECL].uNumEntries, \
		[esi][(sizeof CC_ENTRY)*CC_STDCALL].uNumEntries, \

		[esi][(sizeof CC_ENTRY)*CC_FASTCALL].uNumEntries, \
		g_uNumOfVariables, \
;		[esi][(sizeof CC_ENTRY)*CC_VARIABLE].uNumEntries, \
		edx

;;		[esi][(sizeof CC_ENTRY)*CC_ANSI].uNumEntries, \
;;		[esi][(sizeof CC_ENTRY)*CC_UNICODE].uNumEntries, \

	invoke PrintConsole, addr acSummary, 0

	IFDEF DEBUG
		invoke wsprintf, addr acSummary, $CTA0("weird           : %d\n\n"), [esi][(sizeof CC_ENTRY)*CC_WEIRD].uNumEntries
		invoke PrintConsole, addr acSummary, 0
	ENDIF

	assume esi:nothing

	ret

PrintSummary endp

;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
;                                        PrintLogo                                                  
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

PrintLogo proc

.const
szBuiltOn			db " ("
					date
					db ").", 0
cbBuiltOn			equ $-szBuiltOn
.code

	invoke PrintConsole, $CTA0("\nPrototype Generator"), FOREGROUND_GREEN + FOREGROUND_INTENSITY

	invoke PrintConsole, \
	$CTA0(" - Library file to Include file converter.\n"), FOREGROUND_BLUE + FOREGROUND_GREEN

	invoke PrintConsole, addr g_szVersion, FOREGROUND_BLUE + FOREGROUND_GREEN
	invoke PrintConsole, addr szBuiltOn, FOREGROUND_BLUE + FOREGROUND_GREEN

	invoke PrintConsole, \
	$CTA0(" Copyright (C) 2005, Four-F ( four-f@mail.ru )"), FOREGROUND_BLUE + FOREGROUND_GREEN

	invoke PrintConsole, $CTA0("\n\n"), 0

	ret

PrintLogo endp

;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
;                                       PrintUsage                                                  
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

PrintUsage proc

local csbi:CONSOLE_SCREEN_BUFFER_INFO

CTA  "  -nologo  disable the display of the copyright banner\n", szUsageOptions
CTA  "  libname  library (*.lib) file to convert\n\n"
CTA0 "Example: protogen kernel32.lib\n\n"

	invoke GetConsoleScreenBufferInfo, g_hConsoleOutput, addr csbi
	invoke PrintConsole, $CTA0("Usage: protogen [-nologo] libname\n\n"), 0

	invoke SetConsoleTextAttribute, g_hConsoleOutput, FOREGROUND_BLUE + FOREGROUND_INTENSITY
	invoke PrintConsole, $CTA0("Options:\n"), 0

	movzx eax, csbi.wAttributes
	invoke SetConsoleTextAttribute, g_hConsoleOutput, eax

	invoke PrintConsole, addr szUsageOptions, 0

	ret

PrintUsage endp

;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
;                                 MakePathFullIfNeeded                                              
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

MakePathFullIfNeeded proc uses esi pLibName:LPSTR, pac:LPVOID, cb:UINT

; pLibName	- library file name as user specified it in command line
; pac		- pointer to buffer to recieve full patch
; cb		- size of the buffer pointed by pac

	mov esi, pLibName

	; add current directory if needed
	Fix check for arg
	invoke IsFullPathSpecified, esi
	.if eax
		invoke lstrcpy, pac, esi
	.else
		push eax
		invoke GetFullPathName, esi, cb, pac, esp
		pop eax
	.endif

	; add .lib extension if needed
	Fix check for arg
	invoke IsLibExtensionSpecified, esi
	.if eax == FALSE
		invoke lstrcat, pac, addr g_szLibExtension
	.endif

	ret

MakePathFullIfNeeded endp

;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
;                                    MakeExtensionInc                                               
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

MakeExtensionInc proc uses esi edi ebx pPath:LPSTR
    mov esi, pPath
    .if esi != NULL
		invoke fstrlen, esi
		add esi, eax
		sub esi, 4
		mov dword ptr [esi], "cni."
	.endif
	ret
MakeExtensionInc endp

;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
;                                    GetNameFromPath                                                
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

GetNameFromPath proc uses esi pPath:LPSTR


	mov esi, pPath
	.if esi != NULL
		mov ecx, $invoke(fstrlen, esi)
;	    lea edx, [esi][eax-6]
	    lea ecx, [eax-6]
		; search for back slash
	    .while ecx
		    mov al, [esi][ecx]
    		.break .if al == '\'
		    dec ecx
		.endw
	.endif

	.if ecx != 0
		lea eax, [esi][ecx]
		inc eax
	.else
		xor eax, eax
	.endif

    ret

GetNameFromPath endp

;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
;                                 PrintLogoIfUserWantTo                                             
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

PrintLogoIfUserWantTo proc uses ebx

	; Find 'nologo' switch. If not found prints (C) banner

	mov ebx, CL_argc
	dec ebx
	.while ebx
		mov eax, ebx
		shl eax, 2
		mov eax, CL_argv[eax]
		inc eax							; skeep '/' or '-'
		invoke lstrcmpi, eax, $CTA0("nologo")
		.if eax == 0
			; If 'nologo' switch found break
			.break
		.endif
		dec ebx
	.endw

	.if ebx == 0						; not found 'nologo' ?
		invoke PrintLogo				; Print (C) banner
	.endif

	ret

PrintLogoIfUserWantTo endp

;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
;                                  InitCommandSwitches                                              
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

InitCommandSwitches proc

	xor eax, eax
	.if CL_switch['i']
		dec eax							; -1
	.endif
	mov g_keyDirectImport, al

	mov g_keyIncludeType, 'm'			; masm by default

	.if CL_switch['t'] || CL_switch['T']
		mov g_keyIncludeType, 't'
	.elseif CL_switch['f'] || CL_switch['F']
		mov g_keyIncludeType, 'f'
	.elseif CL_switch['n'] || CL_switch['N']
		mov g_keyIncludeType, 'n'
	.endif

	; 0 - no sort, 0Ah - sort ascending, 0Dh - sort descending
	and g_keySort, 0
	.if CL_switch['a'] || CL_switch['A']
		mov g_keySort, 0Ah
	.elseif CL_switch['d'] || CL_switch['D']
		mov g_keySort, 0Dh
	.endif

	ret

InitCommandSwitches endp

;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
;                                WipeStringSpacesFromRight                                          
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

WipeStringSpacesFromRight proc ps:LPSTR, cc:UINT

option PROLOGUE:NONE
option EPILOGUE:NONE

	; An archive member header has the format, in which each field is an ASCII text string
	; that is left justified and padded with spaces to the end of the field.
	; There is no terminating null character in any of these fields.

	; This proc will overwrite those padding spaces with zeroes

	mov eax, [esp+4]			; ps - pointer to the string
	mov ecx, [esp+8]			; cc - number of characters in string
	.while ecx
		dec ecx
		.break .if byte ptr [eax][ecx] != ' '
		and byte ptr [eax][ecx], 0
	.endw

	ret (sizeof DWORD)*2

option PROLOGUE:PROLOGUEDEF
option EPILOGUE:EPILOGUEDEF

WipeStringSpacesFromRight endp

;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
;                                   GetMaxSymbolNameLenght                                          
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

GetMaxSymbolNameLenght proc uses esi edi ebx pSymEntries:LPVOID, uNumberOfSymbols:UINT, fdwAnsiUnicode:DWORD

⌨️ 快捷键说明

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