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

📄 asm_2_htm.asm

📁 一类在vc下编制的压缩解压缩源代码
💻 ASM
📖 第 1 页 / 共 5 页
字号:
;###########################################################################
;###########################################################################
; ABOUT ASM_2_HTM:
;	This is a basic conversion program. It turns any ASM source file
;	into an internet ready HTML document. The user can configure the
;	colors that it uses based on their own preferences, and set it to
;	make all keywords, registers, psuedo-ops, and types capital letters.
;
;###########################################################################
; Program Info:
;	This program requires nothing special. It just runs once the user 
;	selects a source file to convert to HTML.
;
;###########################################################################
;###########################################################################


;###########################################################################
;###########################################################################
; THE COMPILER OPTIONS
;###########################################################################
;###########################################################################

	.386
	.model flat, stdcall
	option casemap :none   ; case sensitive

;###########################################################################
;###########################################################################
; THE INCLUDES SECTION
;###########################################################################
;###########################################################################

	include \masm32\include\windows.inc
	include \masm32\include\comctl32.inc
	include \masm32\include\comdlg32.inc
	include \masm32\include\shell32.inc
	include \masm32\include\user32.inc
	include \masm32\include\kernel32.inc
	include \masm32\include\gdi32.inc
	
	includelib \masm32\lib\comctl32.lib
	includelib \masm32\lib\comdlg32.lib
	includelib \masm32\lib\shell32.lib
	includelib \masm32\lib\gdi32.lib
	includelib \masm32\lib\user32.lib
	includelib \masm32\lib\kernel32.lib

;###########################################################################
;###########################################################################
; LOCAL MACROS
;###########################################################################
;###########################################################################

	szText MACRO Name, Text:VARARG
		LOCAL lbl
		jmp lbl
		Name db Text,0
		lbl:
	ENDM

	m2m MACRO M1, M2
		push		M2
		pop		M1
      ENDM

	return MACRO arg
		mov	eax, arg
        	ret
	ENDM

	RGB MACRO red, green, blue
		xor	eax,eax
		mov	ah,blue
		shl	eax,8
		mov	ah,green
		mov	al,red
	ENDM

	hWrite MACRO handle, buffer, size
		mov	edi, handle
		add	edi, Dest_index
		mov	ecx, 0
		mov	cx, size
		add	Dest_index, ecx
		mov	esi, buffer
		movsb
	ENDM

	hRead MACRO handle, buffer, size
		mov	edi, handle
		add	edi, Spot
		mov	ecx, 0
		mov	cx, size
		add	Spot, ecx
		mov	esi, buffer
		movsb
	ENDM

;#################################################################################
;#################################################################################
; LOCAL PROTOTYPES
;#################################################################################
;#################################################################################

	;==================================
	; Main Program Procedures
	;==================================
	WinMain PROTO  		:DWORD,:DWORD,:DWORD,:DWORD
	WndProc PROTO  		:DWORD,:DWORD,:DWORD,:DWORD
	Open PROTO
	ConvertFile PROTO
	IsKeyword PROTO		:DWORD,:BYTE
	IsPsuedo PROTO		:DWORD,:BYTE
	IsType PROTO		:DWORD,:BYTE
	IsComment PROTO		:DWORD,:BYTE
	IsReg PROTO			:DWORD,:BYTE
	WriteChar PROTO		:BYTE
	Output PROTO		
	UpdateScreen PROTO
	UpdateMenu PROTO
	AboutProc PROTO  		:DWORD,:DWORD,:DWORD,:DWORD
	ColorProc PROTO  		:DWORD,:DWORD,:DWORD,:DWORD
	MiscCenterWnd PROTO	:DWORD,:DWORD
        
;#################################################################################
;#################################################################################
; BEGIN INITIALIZED DATA
;#################################################################################
;#################################################################################

    .data
    
	;==============================
	;Text for the Window Title
	;==============================
    	szDisplayName	db "ASM_2_HTM",0
      
	;==============================
	;Windows handles and Misc
	;==============================
	CommandLine		dd 0	; for the commandline params
	hRGN			dd 0	; Handle to a region
	hOBJ			dd 0	; Handle to an object
	hBRUSH		dd 0	; Handle to the Brush
	hDC			dd 0	; Handle to device context
	hMainWnd		dd 0	; Handle to the main window
	hMenu			dd 0	; Handle to the menu
	hWnd			dd 0	; Handle to a second window
	hInst			dd 0	; Handle to an Instance
	hIcon			dd 0	; Handle to the icon
	hFile			dd 0	; Handle to the file that we open
	Dest_Amount		dd 0	; Holds the index into Dest mem
	Spot			dd 0	; Holds offset into source for expand
	written		dd 0	; Holds our output bytes
	hConv			dd 0	; Holds icon's handle

	;========================================================
	; This is used to pass arguments to wvsprintfA it can 
	; hold up to 4 different args
	;========================================================
	dwArgs		dd 4 dup (0)

	;========================================
	; Used to let us know it's processing
	; and if we need to make caps
	;========================================
	Processing		db 0
	MakeCaps		db 0

	;===========================================
	; This is for adjusting the Working string
	;===========================================
	Time_Count		db 0

	;========================================================
	; For the Source & Destination files used in Conversion
	;========================================================
	hSrc_Memory		dd 0	; Handle to the source file's memory
	hDest_Memory	dd 0	; Handle to the dest. file's memory
	Dest_Size		dd 0	; Holds the true size of the dest file
	Src_Size		dd 0	; Handle to the size of the source file
	Amount_Read		dd 0	; Pointer to the amount read
	
	;===============================
	; Strings for the application
	;===============================
	szClassName		db "ASM_Class",0
	NoHomePage		db "Unable to open www.fastsoftware.com!",0
	Homepage		db "Http://www.fastsoftware.com/",0
	OpenErr		db "Unable to Open file!",0
	OutputErr		db "Error Writing HTML File!",0
	ConvertErr		db "Error Converting File!",0
	szConvert		db "Select a file to convert to HTML!",0
	szMakeSure		db "Error. Make sure you have 6 Hex characters!",0	

	HowUse		db "ASM_2_HTM is a conversion program for programmers, or any",13,10
				db "body who has an assembly language source file that they",13,10
				db "would like to convert to HTML. To use this program just",13,10
				db "open up any assembly language source file and it will auto-",13,10
				db "matically convert that file to an fully internet ready HTML",13,10
				db "document. You can adjust the colors that it uses with the",13,10
				db "Options menu. And you can set it to make all of your",13,10
				db "KEYWORDS, PSUEDO-OPS, and TYPES capital letters ",13,10
				db "with Make Caps......Have fun.",13,10,13,10
				db " - Chris Hobbs",0

	;=======================================================
	; To open a file
	;=======================================================
	szFile		db 300 dup(0)
	szFileTitle		db 300 dup(0)
	ofn	OPENFILENAME <SIZEOF(OPENFILENAME), NULL, NULL,\
			OFFSET szOpenFilter, NULL, NULL, 1h, OFFSET szFile,\
			800, OFFSET szFileTitle, 800, NULL, NULL,\
			OFN_PATHMUSTEXIST,0, 0, 0, 0, 0, 0>

	;=====================================================
	;Initialize the Font structure for generic app then
	; change what is necessary before calls
	;=====================================================
	Font	LOGFONT	<14,0,0,0,FW_NORMAL,\
			0,0,0,ANSI_CHARSET,OUT_DEFAULT_PRECIS,\
			CLIP_STROKE_PRECIS,DEFAULT_QUALITY,\
			DEFAULT_PITCH or FF_SWISS,"MS Sans Serif">

	;===============================================
	; Our buffer to hold result of wvsprintf call
	; for header placements,font, and menu stuff
	;===============================================
	szHeaderBuffer	db 95 dup (0)
	szFontBuffer	db 25 dup (0)
	szBoldBuffer	db 25 dup (0) 
	szMenuBuffer	db 25 dup (0)
	szColorBuffer	db 10	dup (0)
	szHoldArea		db 10 dup (0)

	;===================================
	; This is the maximum size that a 
	; word can be
	;===================================
	szWord		db 41 dup (0)

	;===================================
	; These are for testing keywords
	;===================================
	szTestString	db 20 dup (0)

	;====================================================
	; These are the color defaults these get changed
	;====================================================
	szDEFAULT_COMMENT		db "#00FF00",0
	szDEFAULT_BACKGROUND	db "#000000",0
	szDEFAULT_TEXT		db "#FFFFFF",0
	szDEFAULT_PSUEDO		db "#FF00FF",0
	szDEFAULT_STRING		db "#0000FF",0
	szDEFAULT_TYPE		db "#FF0000",0
	szDEFAULT_REG		db "#FFFF00",0

;#################################################################################
;#################################################################################
; BEGIN CONSTANTS
;#################################################################################
;#################################################################################

	;================================================
	; These are for opening and saving files
	;================================================
szOpenFilter	SBYTE	"Asm Files (*.asm)",0,"*.asm",0,0
szSaveFilter	SBYTE	"HTML Files (*.htm)",0,"*.htm",0,0
szDefExt		SBYTE "htm",0

	;====================================================================
	; These are the templates we use for writing out the HTML stuff
	;====================================================================
szHeaderTemp1	SBYTE "<HTML>",13,10
			SBYTE "<HEAD>",13,10
			SBYTE "<TITLE> %s </TITLE>",13,10,0

szHeaderTemp2	SBYTE "</HEAD>",13,10
			SBYTE "<BODY BGCOLOR=%s TEXT=%s><pre>",13,10,0

szFontTemp		SBYTE "<FONT COLOR=%s>",0
szEndFont		SBYTE "</FONT>",0
szBoldTemp		SBYTE "<B>%s</B>",0

	;================================
	; This is how we end every file
	;================================
szEnding		SBYTE	"</pre></BODY></HTML>",0

	;================================================
	; These hold the templates for the menu strings
	;================================================
szMenuBackTemp	SBYTE "Background: %s",0
szMenuTextTemp	SBYTE "Text: %s",0
szMenuCommentTemp	SBYTE "Comments: %s",0
szMenuStringTemp	SBYTE "Strings: %s",0
szMenuTypeTemp	SBYTE "Types: %s",0
szMenuPsuedoTemp	SBYTE "Psuedo-Op: %s",0
szMenuRegTemp	SBYTE "Registers: %s",0

	;=========================================================
	; This is the template for when they specify a new color
	;=========================================================
szColorTemp		SBYTE "#%s",0

	;================================================
	; These hold the defaults for restoration
	; DO NOT ALTER IN CODE
	;================================================
DEFAULT_COMMENT		SBYTE "#00FF00",0
DEFAULT_BACKGROUND	SBYTE "#000000",0
DEFAULT_TEXT		SBYTE "#FFFFFF",0
DEFAULT_PSUEDO		SBYTE "#FF00FF",0
DEFAULT_STRING		SBYTE "#0000FF",0
DEFAULT_TYPE		SBYTE "#FF0000",0
DEFAULT_REGS		SBYTE "#FFFF00",0

	;==================================
	; These are for the special signs
	;==================================
GREATER_SIGN		SBYTE "&gt;",0
LESS_SIGN			SBYTE "&lt;",0
AMPERSAND_SIGN		SBYTE	"&amp;",0

	;=================================
	; This is so they know we haven't 
	; locked up and are processing
	;=================================
Working			SBYTE "Working....."

;#################################################################################
;#################################################################################
; BEGIN EQUATES
;#################################################################################
;#################################################################################

	;=================
	;Utility Equates
	;=================
FALSE		equ	0
TRUE		equ	1

	;================
	; resource IDs
	;================
IDI_ASM		equ	500
IDM_MENU		equ	600
IDD_ABOUT		equ	700
IDD_COLOR		equ	800
ID_COLOR		equ	9000

	;================
	; Menu ID's
	;================
IDM_CONVERT		equ	1000
IDM_EXIT		equ	1500
IDM_BACKGROUND	equ	2000
IDM_TEXT		equ	2010
IDM_COMMENT		equ	2020
IDM_STRING		equ	2030
IDM_TYPE		equ	2040
IDM_PSUEDO		equ	2050
IDM_REG		equ	2060
IDM_RESTORE		equ	2500
IDM_MAKECAPS	equ	2600
IDM_HOW		equ	3400
IDM_ABOUT		equ	3500

	;================
	; STRING TABLES 
	;================
COMMENT_BASE	equ	1000h
STRING_BASE		equ	2000h
PSUEDO_BASE		equ	3000h
KEYWORD_BASE	equ	4000h
TYPE_BASE		equ	5000h
REG_BASE		equ	6000h
	
	;================
	; Number of each
	;================
NUM_KEYWORD		equ	192
NUM_PSUEDO		equ	88
NUM_TYPE		equ	18
NUM_REG		equ	28

	;=================
	; Max size of word
	;=================
MAX_WORD_SIZE	equ	40

;#################################################################################
;#################################################################################
; BEGIN THE CODE SECTION
;#################################################################################
;#################################################################################

  .code

start:
	invoke GetModuleHandle, NULL
	mov	hInst, eax

	invoke GetCommandLine
	mov	CommandLine, eax

	invoke WinMain,hInst,NULL,CommandLine,SW_SHOWDEFAULT
	invoke ExitProcess,eax

;#########################################################################

WinMain proc hInstance	:DWORD,
		hPrevInst	:DWORD,
		CmdLine	:DWORD,
		CmdShow	:DWORD

	;====================
	; Put LOCALs on stack
	;====================

	LOCAL wc   :WNDCLASSEX
	LOCAL msg  :MSG
	
	LOCAL B_RECT	:RECT	   ; a rectangle struct
	LOCAL hFONT		:DWORD   ; handle to the font
	LOCAL Wwd  		:DWORD
	LOCAL Wht  		:DWORD
	LOCAL Wtx  		:DWORD
	LOCAL Wty  		:DWORD

	;==================================================
	; Fill WNDCLASSEX structure with required variables
	;==================================================

	mov	wc.cbSize,sizeof WNDCLASSEX
	mov	wc.style,CS_HREDRAW or CS_VREDRAW \
				or CS_BYTEALIGNWINDOW
	mov	wc.lpfnWndProc,offset WndProc
	mov	wc.cbClsExtra,NULL
	mov	wc.cbWndExtra,NULL
	m2m	wc.hInstance,hInst   ;<< NOTE: macro not mnemonic
	mov	wc.hbrBackground,COLOR_BACKGROUND
	mov	wc.lpszMenuName,NULL
	mov	wc.lpszClassName,offset szClassName
	invoke LoadIcon,hInst,IDI_ASM    ; icon ID
	mov	hIcon,eax
	mov	wc.hIcon,eax
	invoke LoadCursor,NULL,IDC_ARROW
	mov	wc.hCursor,eax
	mov	wc.hIconSm,0

	invoke RegisterClassEx, ADDR wc

	;================================
	; Create window at following size

⌨️ 快捷键说明

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