New PEWRSEC    [by BlueOwl]
[executable tool in a zip archive]

  

; New PEWRSEC by BlueOwl
;
; As some people using (or wanting to use) TASM under windows
; seem to be having troubles with the old ones (i had trouble
; too), i  decided to  write a new win32 one.  Its  a  simple
; commandline one (can be used from a batch or make file) and
; it does not show any message. As an added bonus it does not
; use a buffer for the file so input any file you like ;)


include '%fasminc%/win32ax.inc'

.data

	fhand	dd ?
	mzsize	dd ?
	nbr	dd ?
	section_count dd ?
	dir_count dd ?
	section_point dd ?

	section_c dd ?

.code

  start:
	invoke	GetCommandLine
	xchg	eax, esi
g_e:	lodsb
	cmp	al, 20h
	jnz	g_e

	invoke	CreateFile,esi,GENERIC_READ or GENERIC_WRITE,FILE_SHARE_READ,0,\
		OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0
	cmp	eax, INVALID_HANDLE_VALUE
	jz	error_out
	mov     [fhand], eax

	invoke	SetFilePointer,[fhand],03Ch,0,FILE_BEGIN
	invoke	ReadFile,[fhand],mzsize,4,nbr,0

	mov	eax, [mzsize]
	add	eax, 6		        ; eax = offset of number of sections

	invoke	SetFilePointer,[fhand],eax,0,FILE_BEGIN
	invoke	ReadFile,[fhand],section_count,2,nbr,0

	mov	eax, [mzsize]
	add	eax, 116	        ; eax = offset of number of dirs
	mov     [section_point], eax

	invoke	SetFilePointer,[fhand],eax,0,FILE_BEGIN
	invoke	ReadFile,[fhand],dir_count,2,nbr,0

	mov	eax, [dir_count]
	shl	eax, 3		        ; *8
	add     [section_point], eax

	add	dword [section_point], 36+4	  ; point to charasteristics

set_write_secs:
	invoke	SetFilePointer,[fhand],[section_point],0,FILE_BEGIN
	invoke	ReadFile,[fhand],section_c,4,nbr,0

	or	dword [section_c], 80000000h or 20000000h or 00000020h

	invoke	SetFilePointer,[fhand],[section_point],0,FILE_BEGIN
	invoke	WriteFile,[fhand],section_c,4,nbr,0

	add	dword [section_point], 40

	dec	dword [section_count]
	jnz	set_write_secs

	invoke	CloseHandle,[fhand]

error_out:

	ret

	db      "BlueOwl 2004. Have a nice day :)"

.end start