Skip to content

Instantly share code, notes, and snippets.

@zamabuvaraeu
Created October 18, 2025 02:37
Show Gist options
  • Select an option

  • Save zamabuvaraeu/94e1b97f38021d54e03cd13c6e1b86b9 to your computer and use it in GitHub Desktop.

Select an option

Save zamabuvaraeu/94e1b97f38021d54e03cd13c6e1b86b9 to your computer and use it in GitHub Desktop.
Нарушение безопасности: не забывайте обнулять вещи на которые вам наплевать

Не забывайте обнулять вещи, на которые вам наплевать:

#include once "windows.bi"

Type FileHeader
	dwMagic As Long
	dwVersion As Long
	szComment As ZString * (255 + 1)
	cbData As Long
End Type

Function SafeToFile( _
		ByVal hFile As HANDLE, _
		ByVal pszComment As ZString Ptr, _
		ByVal cbData As Long, _
		ByVal bData As UByte _
	)As Integer

	Dim fh As FileHeader Ptr = Allocate(SizeOf(FileHeader))

	fh->dwMagic = 16
	fh->dwVersion = 1
	lstrcpyA(@fh->szComment, pszComment)
	fh->cbData = cbData

	Dim cbWritten As DWORD = Any
	WriteFile(hFile, fh, SizeOf(FileHeader), @cbWritten, NULL)
	WriteFile(hFile, @bData, SizeOf(UByte), @cbWritten, NULL)

	Return 0

End Function

Dim hFile As HANDLE = CreateFileA( _
	"file.bin", _
	GENERIC_WRITE, _
	0, _
	NULL, _
	CREATE_ALWAYS, _
	FILE_ATTRIBUTE_NORMAL, _
	NULL _
)

Const Comment = Str("this is a comment")

If hFile <> INVALID_HANDLE_VALUE Then
	SafeToFile( _
		hFile, _
		@Comment, _
		256, _
		1 _
	)
	CloseHandle(hFile)
End If
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment