Skip to content

Development

Joachim Metz edited this page Jul 15, 2022 · 4 revisions

VB.Net development

Open and close

Imports SMRaw

Module OpenClose

Function Main(ByVal args() As String) As Integer
  Dim handle As New SMRaw.Handle
  Dim smraw As New SMRaw.SMRaw

  Dim program As String = "OpenClose.exe"

  Console.WriteLine(program + " (smraw.net " + smraw.GetVersion() + ")")

  If args.Length() < 1 Then
    Console.WriteLine("Usage: " + program + " filename(s)")

    Return 1
  End If

  handle.Open(args, handle.GetAccessFlagsRead())

  handle.Close()

  Console.WriteLine("")

  Return 0
End Function

End Module

Glob

Imports SMRaw

Module Glob

Function Main(ByVal args() As String) As Integer
        Dim handle As New SMRaw.Handle
        Dim smraw As New SMRaw.SMRaw

        Dim filenames As Array = Nothing
        Dim filename As String = Nothing
        Dim program As String  = "Glob.exe"

        Console.WriteLine(program + " (smraw.net " + smraw.GetVersion() + ")")

        If args.Length() <> 1 Then
                Console.WriteLine("Usage: " + program + " filename")

                Return 1
        End If

        filenames = handle.Glob(args(0))

        If filenames.Length() > 0 Then
                Console.WriteLine("Filenames:")

                For Each filename In filenames
                        Console.WriteLine(filename)
                Next
        End If

        Console.WriteLine("")

        Return 0
End Function

End Module

MD5sum

Imports MD5net
Imports SMRaw

Module MD5sum

Function BinaryToHexString(ByVal data() As Byte) As String
    Dim string_builder As New System.Text.StringBuilder( data.Length() * 2 )

    For Each value As Byte In data
        string_builder.Append(value.ToString("X2"))
    Next

    Return string_builder.ToString().ToLower()
End Function

Function Main(ByVal args() As String) As Integer
        Dim md5_context As New MD5net.Context
        Dim handle As New SMRaw.Handle
        Dim smraw As New SMRaw.SMRaw

        Dim filenames As Array    = Nothing
        Dim md5_hash() As Byte    = Nothing
        Dim program As String     = "MD5sum.exe"
        Dim media_size As UInt64  = 0
        Dim read_count As Integer = 0
        Dim read_size As Integer  = 0

        Dim buffer(4096) As Byte

        Console.WriteLine(program + " (smraw.net " + smraw.GetVersion() + ")")

        If args.Length() < 1 Then
                Console.WriteLine("Usage: " + program + " filename")

                Return 1
        End If

        If args.Length() = 1 Then
                filenames = handle.Glob(args(0))
        Else
                filenames = args
        End If

        If filenames.Length() <= 0 Then
                Console.WriteLine("Unable to determine filename(s)")

                Return 1
        End If

        handle.Open(filenames, handle.GetAccessFlagsRead())

        media_size = handle.GetMediaSize()

        While media_size > 0
                If media_size > 4096 Then
                        read_size = 4096
                Else
                        read_size = media_size
                End If

                read_count = handle.ReadBuffer(buffer, read_size)

                If read_count <> read_size Then
                        Console.WriteLine("Unable to read from files")

                        Return 1
                End If

                md5_context.Update(buffer, read_size)

                media_size -= read_size
        End While

        handle.Close()

        md5_hash = md5_context.GetHash()

    Console.WriteLine("MD5: " + BinaryToHexString(md5_hash))

        Console.WriteLine("")

        Return 0
End Function

End Module
Clone this wiki locally