Hi Rene,

There are numerous tools available to convert between .net languages with
one mouse click.

I did this with SharpDevelop 4 http://www.icsharpcode.net/OpenSource/SD/

See converted function below.

Wish you luck.

Niels

'
' * Created by SharpDevelop.
' * User: kooiman
' * Date: 2012-07-18
' * Time: 12:19
' *
' * To change this template use Tools | Options | Coding | Edit Standard
Headers.
'
Imports System

Namespace Sample
    ''' <summary>
    ''' Description of Class1.
    ''' </summary>
    Public Class XpsCreate

        Private Sub WriteObfuscatedStream(resourceName As String,
stream As Stream,
resource As String)
            Dim bufSize As Integer = &H1000
            Dim guidByteSize As Integer = 16
            Dim obfuscatedByte As Integer = 32

            ' Get the GUID byte from the resource name.  Typical Font name:
            '    /Resources/Fonts/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.ODTTF
            Dim startPos As Integer = resourceName.LastIndexOf("/"C) + 1
            Dim length As Integer = resourceName.LastIndexOf("."C) -
startPos
            resourceName = resourceName.Substring(startPos, length)

            Dim guid As New Guid(resourceName)

            Dim guidString As String = guid.ToString("N")

            ' Parsing the guid string and coverted into byte value
            Dim guidBytes As Byte() = New Byte(guidByteSize - 1) {}
            For i As Integer = 0 To guidBytes.Length - 1
                guidBytes(i) = Convert.ToByte(guidString.Substring(i * 2,
2), 16)
            Next

            Using filestream As New FileStream(resource, FileMode.Open)
                ' XOR the first 32 bytes of the source
                ' resource stream with GUID byte.
                Dim buf As Byte() = New Byte(obfuscatedByte - 1) {}
                filestream.Read(buf, 0, obfuscatedByte)

                For i As Integer = 0 To obfuscatedByte - 1
                    Dim guidBytesPos As Integer = guidBytes.Length -
(i Mod guidBytes.Length)
- 1
                    buf(i) = buf(i) Xor guidBytes(guidBytesPos)
                Next
                stream.Write(buf, 0, obfuscatedByte)

                ' copy remaining stream from source without obfuscation
                buf = New Byte(bufSize - 1) {}

                Dim bytesRead As Integer = 0
                While (InlineAssignHelper(bytesRead, filestream.Read(buf,
0, bufSize))) > 0
                    stream.Write(buf, 0, bytesRead)
                End While
            End Using
        End Sub
        Private Shared Function InlineAssignHelper(Of T)(ByRef target As T,
value As T) As T
            target = value
            Return value
        End Function
        ' end:WriteObfuscatedStream()
    End Class
    ' end:class XpsCreate
End Namespace


On Tue, Jul 17, 2012 at 5:13 PM, Rene Malingre <rene.malin...@gmail.com>wrote:

> Hello all.  Please be nice, I am trying to learn VB.NET.  I do not know
> c# at all.
>
> I wish to convert a routine from c# to vb.net.  I think I am messing up
> the use of byte data type.  Can someone please tell me if I have gone wrong?
>
> This is sample code from Microsoft; I am trying to write a program that
> generates an XPS file, and I am ending up with zero length resources, and I
> think it is from this routine.
>
> Thanks so much.
>
>
> *C# routine:*
>  private void WriteObfuscatedStream(
>         string resourceName, Stream stream, string resource)
>     {
>         int bufSize = 0x1000;
>         int guidByteSize = 16;
>         int obfuscatedByte = 32;
>
>         // Get the GUID byte from the resource name.  Typical Font name:
>         //    /Resources/Fonts/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.ODTTF
>         int startPos = resourceName.LastIndexOf('/') + 1;
>         int length = resourceName.LastIndexOf('.') - startPos;
>         resourceName = resourceName.Substring(startPos, length);
>
>         Guid guid = new Guid(resourceName);
>
>         string guidString = guid.ToString("N");
>
>         // Parsing the guid string and coverted into byte value
>         byte[] guidBytes = new byte[guidByteSize];
>         for (int i = 0; i < guidBytes.Length; i++)
>         {
>             guidBytes[i] = Convert.ToByte(guidString.Substring(i * 2, 2),
> 16);
>         }
>
>         using (FileStream filestream = new FileStream(resource,
> FileMode.Open))
>         {
>             // XOR the first 32 bytes of the source
>             // resource stream with GUID byte.
>             byte[] buf = new byte[obfuscatedByte];
>             filestream.Read(buf, 0, obfuscatedByte);
>
>             for (int i = 0; i < obfuscatedByte; i++)
>             {
>                 int guidBytesPos = guidBytes.Length - (i %
> guidBytes.Length) - 1;
>                 buf[i] ^= guidBytes[guidBytesPos];
>             }
>             stream.Write(buf, 0, obfuscatedByte);
>
>             // copy remaining stream from source without obfuscation
>             buf = new byte[bufSize];
>
>             int bytesRead = 0;
>             while ((bytesRead = filestream.Read(buf, 0, bufSize)) > 0)
>             {
>                 stream.Write(buf, 0, bytesRead);
>             }
>         }
>     }// end:WriteObfuscatedStream()
>
> }// end:class XpsCreate
>
> My attempt at VB.NET
>     ' ------------------------- WriteObfuscatedStream
> ------------------------
>     Private Sub WriteObfuscatedStream(ByRef resourceName As String, ByRef
> stream As Stream, ByRef resource As String)
>
>         Const bufSize As Integer = 4096
>         Dim guidByteSize As Integer = 16
>         Dim obfuscatedByte As Integer = 32
>
>         ' Get the GUID byte from the resource name.  Typical Font name:
>         '    /Resources/Fonts/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.ODTTF
>         Dim startPos As Integer = resourceName.LastIndexOf("/") + 1
>         Dim length As Integer = resourceName.LastIndexOf(".") - startPos
>         resourceName = resourceName.Substring(startPos, length)
>
>         Dim guid As Guid = New Guid(resourceName)
>
>         Dim guidString As String = guid.ToString("N")
>
>         ' Parsing the guid string and coverted into byte value
>         Dim guidBytes(0 To guidByteSize - 1) As Byte
>         Dim i As Integer
>
>         For i = 0 To guidBytes.Length - 1
>             guidBytes(i) = Convert.ToByte(guidString.Substring(i * 2, 2),
> 16)
>         Next
>         Dim filestream As FileStream = New FileStream(resource,
> FileMode.Open)
>         ' XOR the first 32 bytes of the source
>         ' resource stream with GUID byte.
>         Dim buf(0 To obfuscatedByte - 1) As Byte
>         filestream.Read(buf, 0, obfuscatedByte)
>         Dim guidBytesPos As Integer
>
>         For i = 0 To obfuscatedByte - 1
>             guidBytesPos = guidBytes.Length - (i Mod guidBytes.Length) - 1
>             buf(i) = buf(i) Xor guidBytes(guidBytesPos)
>         Next
>
>         stream.Write(buf, 0, obfuscatedByte)
>
>         ' copy remaining stream from source without obfuscation
>         ReDim buf(0 To bufSize - 1)
>
>         Dim bytesRead As Integer = 0
>         While ((bytesRead = filestream.Read(buf, 0, bufSize)) > 0)
>             stream.Write(buf, 0, bytesRead)
>         End While
>         filestream.Close()
>
>     End Sub ':WriteObfuscatedStream()
>
>  --
> You received this message because you are subscribed to the Google
> Groups "DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML
> Web Services,.NET Remoting" group.
> To post to this group, send email to dotnetdevelopment@googlegroups.com
> To unsubscribe from this group, send email to
> dotnetdevelopment+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/dotnetdevelopment?hl=en?hl=en
> or visit the group website at http://megasolutions.net
>

-- 
You received this message because you are subscribed to the Google
Groups "DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML
Web Services,.NET Remoting" group.
To post to this group, send email to dotnetdevelopment@googlegroups.com
To unsubscribe from this group, send email to
dotnetdevelopment+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/dotnetdevelopment?hl=en?hl=en
or visit the group website at http://megasolutions.net

Reply via email to