Imports System.IO
Public Class Form1
' Inherits XmlDocument
Shared ReadOnly encode As Byte() = New Byte() {&H8C, &H8F, &H8E, &H89, &H88, &H8B, &H8A, &H85, &H84, &H87, &H86, &H81, &H80, &H83, &H82, &H8D, &HBC, &HBF, &HBE, &HB9, &HB8, &HBB, &HBA, &HB5, &HB4, &HB7, &HB6, &HB1, &HB0, &HB3, &HB2, &HAD, &HAC, &HAF, &HAE, &HA9, &HA8, &HAB, &HAA, &HA5, &HA4, &HA7, &HA6, &HA1, &HA0, &HA3, &HA2, &HDD, &HDC, &HDF, &HDE, &HD9, &HD8, &HDB, &HDA, &HD5, &HD4, &HD7, &HD6, &HD1, &HD0, &HD3, &HD2, &HCD, &HCC, &HCF, &HCE, &HC9, &HC8, &HCB, &HCA, &HC5, &HC4, &HC7, &HC6, &HC1, &HC0, &HC3, &HC2, &HFD, &HFC, &HFF, &HFE, &HF9, &HF8, &HFB, &HFA, &HF5, &HF4, &HF7, &HF6, &HF1, &HF0, &HF3, &HF2, &HED, &HEC, &HEF, &HEE, &HE9, &HE8, &HEB, &HEA, &HE5, &HE4, &HE7, &HE6, &HE1, &HE0, &HE3, &HE2, &H1D, &H1C, &H1F, &H1E, &H19, &H18, &H1B, &H1A, &H15, &H14, &H17, &H16, &H11, &H10, &H13, &H12, &HD, &HC, &HF, &HE, &H9, &H8, &HB, &HA, &H5, &H4, &H7, &H6, &H1, &H0, &H3, &H2, &H3D, &H3C, &H3F, &H3E, &H39, &H38, &H3B, &H3A, &H35, &H34, &H37, &H36, &H31, &H30, &H33, &H32, &H2D, &H2C, &H2F, &H2E, &H29, &H28, &H2B, &H2A, &H25, &H24, &H27, &H26, &H21, &H20, &H23, &H22, &H5D, &H5C, &H5F, &H5E, &H59, &H58, &H5B, &H5A, &H55, &H54, &H57, &H56, &H51, &H50, &H3, &H52, &H4D, &H4C, &H4F, &H4E, &H49, &H48, &H4B, &H4A, &H45, &H44, &H47, &H46, &H41, &H40, &H43, &H42, &H7D, &H7C, &H7F, &H7E, &H79, &H78, &H7B, &H7A, &H75, &H74, &H77, &H76, &H71, &H70, &H73, &H72, &H6D, &H6C, &H6F, &H6E, &H69, &H68, &H6B, &H6A, &H65, &H64, &H67, &H66, &H61, &H60, &H63, &H62, &H9D, &H9C, &H9F, &H9E, &H99, &H98, &H9B, &H9A, &H95, &H94, &H97, &H96, &H91, &H90, &H93, &H92, &HFF}
Shared ReadOnly decode As Byte() = New Byte() {&H8C, &H8B, &H8E, &H8D, &H88, &H87, &H8A, &H89, &H84, &H83, &H86, &H85, &H80, &H7F, &H82, &H81, &H7C, &H7B, &H7E, &H7D, &H78, &H77, &H7A, &H79, &H74, &H73, &H76, &H75, &H70, &H6F, &H72, &H71, &HAC, &HAB, &HAE, &HAD, &HA8, &HA7, &HAA, &HA9, &HA4, &HA3, &HA6, &HA5, &HA0, &H9F, &HA2, &HA1, &H9C, &H9B, &H9E, &H9D, &H98, &H97, &H9A, &H99, &H94, &H93, &H96, &H95, &H90, &H8F, &H92, &H91, &HCC, &HCB, &HCE, &HCD, &HC8, &HC7, &HCA, &HC9, &HC4, &HC3, &HC6, &HC5, &HC0, &HBF, &HC2, &HC1, &HBC, &HBB, &HBE, &HBD, &HB8, &HB7, &HBA, &HB9, &HB4, &HB3, &HB6, &HB5, &HB0, &HAF, &HB2, &HB1, &HEC, &HEB, &HEE, &HED, &HE8, &HE7, &HEA, &HE9, &HE4, &HE3, &HE6, &HE5, &HE0, &HDF, &HE2, &HE1, &HDC, &HDB, &HDE, &HDD, &HD8, &HD7, &HDA, &HD9, &HD4, &HD3, &HD6, &HD5, &HD0, &HCF, &HD2, &HD1, &HC, &HB, &HE, &HD, &H8, &H7, &HA, &H9, &H4, &H3, &H6, &H5, &H0, &HF, &H2, &H1, &HFC, &HFB, &HFE, &HFD, &HF8, &HF7, &HFA, &HF9, &HF4, &HF3, &HF6, &HF5, &HF0, &HEF, &HF2, &HF1, &H2C, &H2B, &H2E, &H2D, &H28, &H27, &H2A, &H29, &H24, &H23, &H26, &H25, &H20, &H1F, &H22, &H21, &H1C, &H1B, &H1E, &H1D, &H18, &H17, &H1A, &H19, &H14, &H13, &H16, &H15, &H10, &HF, &H12, &H11, &H4C, &H4B, &H4E, &H4D, &H48, &H47, &H4A, &H49, &H44, &H43, &H46, &H45, &H40, &H3F, &H42, &H41, &H3C, &H3B, &H3E, &H3D, &H38, &H37, &H3A, &H39, &H34, &H33, &H36, &H35, &H30, &H2F, &H32, &H31, &H6C, &H6B, &H6E, &H6D, &H68, &H67, &H6A, &H69, &H64, &H63, &H66, &H65, &H60, &H5F, &H62, &H61, &H5C, &H5B, &H5E, &H5D, &H58, &H57, &H5A, &H59, &H54, &H53, &H56, &H55, &H50, &H4F, &H52, &H51}
Public Sub LoadFromDstFile()
Dim filename As String
Dim OpenFileDialog As New OpenFileDialog
OpenFileDialog.Filter = "файл подшивки (dst)|*.dst"
If (OpenFileDialog.ShowDialog(Me) = System.Windows.Forms.DialogResult.OK) Then
filename = OpenFileDialog.FileName
If Not File.
Exists(filename
) Then Throw New FileNotFoundException()
End If
Dim xmlSource
As Byte() = File.
ReadAllBytes(Environment.
ExpandEnvironmentVariables(filename
)) Dim ms = New MemoryStream(DecryptFile(xmlSource))
Dim strDST As String = New StreamReader(ms).ReadToEnd
rtfPrev.Text = strDST
' Получаем имя файла без расширения
Dim fileNameWithoutExtension As String = Path.GetFileNameWithoutExtension(filename)
' Получаем путь без имени файла
Dim directoryPath As String = Path.GetDirectoryName(filename)
' Запись текста в файл
File.
WriteAllText(directoryPath
& "\" & fileNameWithoutExtension
& ".xml", strDST, System.
Text.
Encoding.
UTF8) MsgBox("Файл сохрянён рядом с исходным" & vbCrLf & directoryPath & "\" & fileNameWithoutExtension & ".xml")
End If
End Sub
Public Sub SaveAsDstFile()
Dim filename As String
Dim OpenFileDialog As New OpenFileDialog
OpenFileDialog.Filter = "файл подшивки (xml)|*.xml"
If (OpenFileDialog.ShowDialog(Me) = System.Windows.Forms.DialogResult.OK) Then
filename = OpenFileDialog.FileName
Dim ms = New MemoryStream()
Using fileStream
As FileStream
= File.
OpenRead(filename
) fileStream.CopyTo(ms)
End Using
rtfPrev.Text = System.Text.Encoding.UTF8.GetString(ms.ToArray())
' Получаем имя файла без расширения
Dim fileNameWithoutExtension As String = Path.GetFileNameWithoutExtension(filename)
' Получаем путь без имени файла
Dim directoryPath As String = Path.GetDirectoryName(filename)
' Me.Save(ms)
File.
WriteAllBytes(directoryPath
& "\" & fileNameWithoutExtension
& "-E.dst", EncryptFile
(ms.
ToArray())) MsgBox("Файл сохрянён рядом с исходным" & vbCrLf & directoryPath & "\" & fileNameWithoutExtension & "-E.dst")
End If
End Sub
Private Shared Function DecryptFile(ByVal bytes As IEnumerable(Of Byte)) As Byte()
Return bytes.[Select](Function(t) decode(t)).ToArray()
End Function
Private Shared Function EncryptFile(ByVal bytes As IEnumerable(Of Byte)) As Byte()
Return bytes.[Select](Function(t) encode(t)).ToArray()
End Function
Public Shared Function CreateGuid() As String
Return "g" & Guid.NewGuid().ToString().ToUpper()
End Function
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
LoadFromDstFile()
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
SaveAsDstFile()
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
rtfByte.Text = "encode" & vbTab & vbTab & "decode"
For i = 0 To encode.Length - 1
rtfByte.Text = rtfByte.Text & vbCrLf & encode(i) & "-" & Chr(encode(i)) & vbTab & vbTab & decode(i) & "-" & Chr(decode(i))
Next
End Sub
End Class