Skip to content

Commit

Permalink
WIP, .net35
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Bochkov committed Dec 14, 2016
1 parent f6510ef commit c3fe113
Show file tree
Hide file tree
Showing 9 changed files with 136 additions and 125 deletions.
97 changes: 22 additions & 75 deletions PasswordChanger1C/AccessFunctions.vb
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,12 @@ Module AccessFunctions

End Sub

Sub WritePasswordIntoInfoBaseIB(FileName As String, PageHeader As PageParams, UserID As Byte(), NewData As Byte(), DataPos As Integer, DataSize As Integer)
Sub WritePasswordIntoInfoBaseIB(FileName As String, PageHeader As PageParams, UserID As Byte(), OldData As Byte(), NewData As Byte(), DataPos As Integer, DataSize As Integer)

If PageHeader.DatabaseVersion.StartsWith("8.3") Then
DatabaseAccess838.WritePasswordIntoInfoBaseIB(FileName, PageHeader, UserID, OldData, NewData, DataPos, DataSize)
Return
End If

Dim PageSize As Integer = PageHeader.PageSize

Expand All @@ -165,30 +170,30 @@ Module AccessFunctions

DataPage = ReadPage(reader, bytesBlock1)

Dim TotalBlocks = 0
For Each ST In DataPage.StorageTables
TotalBlocks = TotalBlocks + ST.DataBlocks.Count
Next
Dim TotalBlocks = 0
For Each ST In DataPage.StorageTables
TotalBlocks = TotalBlocks + ST.DataBlocks.Count
Next

bytesBlock = New Byte(PageSize * TotalBlocks - 1) {}
bytesBlock = New Byte(PageSize * TotalBlocks - 1) {}

Dim i = 0
For Each ST In DataPage.StorageTables
Dim i = 0
For Each ST In DataPage.StorageTables

For Each DB In ST.DataBlocks
Dim TempBlock() As Byte = New Byte(PageSize - 1) {}
reader.BaseStream.Seek(DB * PageSize, SeekOrigin.Begin)
reader.Read(TempBlock, 0, PageSize)
For Each ElemByte In TempBlock
bytesBlock(i) = ElemByte
i = i + 1
Next
For Each DB In ST.DataBlocks
Dim TempBlock() As Byte = New Byte(PageSize - 1) {}
reader.BaseStream.Seek(DB * PageSize, SeekOrigin.Begin)
reader.Read(TempBlock, 0, PageSize)
For Each ElemByte In TempBlock
bytesBlock(i) = ElemByte
i = i + 1
Next
Next
Next



reader.Close()
reader.Close()


Dim NextBlock = DataPos
Expand Down Expand Up @@ -242,62 +247,4 @@ Module AccessFunctions
End Sub


Sub WritePasswordIntoInfoBaseIB83(FileName As String, PageHeader As PageParams, UserID As Byte(), NewData As Byte(), DataPos As Integer, DataSize As Integer)

Dim PageSize As Integer = PageHeader.PageSize

'Dim fs As New FileStream(FileName, FileMode.Open, FileAccess.ReadWrite, FileShare.Write)
'Dim reader As New BinaryReader(fs)

'Dim bytesBlock1() As Byte = New Byte(PageSize - 1) {}
'reader.BaseStream.Seek(PageHeader.BlockBlob * PageSize, SeekOrigin.Begin)
'reader.Read(bytesBlock1, 0, PageSize)

'Dim DataPage As PageParams = Nothing
'Dim bytesBlock() As Byte

'DataPage = ReadObjectPage83(reader, bytesBlock1, PageSize)
'bytesBlock = DataPage.BinaryData
'reader.Close()


'Dim NextBlock = DataPos
'Dim Pos = DataPos * 256
'Dim ii = 0
'While NextBlock > 0

' NextBlock = BitConverter.ToInt32(bytesBlock, Pos)
' Dim BlockSize = BitConverter.ToInt16(bytesBlock, Pos + 4)

' For j = 0 To BlockSize - 1
' bytesBlock(Pos + 6 + j) = NewData(ii)
' ii = ii + 1
' Next
' Pos = NextBlock * 256
'End While

'fs = New FileStream(FileName, FileMode.Open, FileAccess.ReadWrite, FileShare.Write)
'Dim writer As New BinaryWriter(fs)

'ii = 0
'For Each ST In DataPage.StorageTables
' For Each DB In ST.DataBlocks
' Dim TempBlock() As Byte = New Byte(PageSize - 1) {}
' For j = 0 To PageSize - 1
' TempBlock(j) = bytesBlock(ii)
' ii = ii + 1
' Next

' writer.Seek(DB * PageSize, SeekOrigin.Begin)
' writer.Write(TempBlock)

' Next
'Next


'writer.Close()

End Sub


End Module
1 change: 1 addition & 0 deletions PasswordChanger1C/DatabaseAccess8214.vb
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@ Module DatabaseAccess8214

Dict.Add("DATA_KEYSIZE", DataKeySize)
Dict.Add("DATA_KEY", DataKey)
Dict.Add("DATA_BINARY", BytesValTemp)

ElseIf Field.Type = "NT" Then
'Строка неограниченной длины
Expand Down
34 changes: 34 additions & 0 deletions PasswordChanger1C/DatabaseAccess838.vb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Imports System.IO
Imports System.Text
Imports System.Linq

Module DatabaseAccess838

Expand Down Expand Up @@ -178,6 +179,7 @@ Module DatabaseAccess838

Dict.Add("DATA_KEYSIZE", DataKeySize)
Dict.Add("DATA_KEY", DataKey)
Dict.Add("DATA_BINARY", BytesValTemp)

ElseIf Field.Type = "NT" Then
'Строка неограниченной длины
Expand Down Expand Up @@ -327,4 +329,36 @@ Module DatabaseAccess838

End Function

Sub WritePasswordIntoInfoBaseIB(FileName As String, PageHeader As PageParams, UserID As Byte(), OldData As Byte(), NewData As Byte(), DataPos As Integer, DataSize As Integer)

Dim fs As New FileStream(FileName, FileMode.Open, FileAccess.ReadWrite, FileShare.Write)
Dim reader As New BinaryReader(fs)

Dim PageSize = PageHeader.PageSize
Dim BlockBlob = PageHeader.BlockBlob

Dim BytesBlobBlock() As Byte = New Byte(PageSize - 1) {}
reader.BaseStream.Seek(BlockBlob * PageSize, SeekOrigin.Begin)
reader.Read(BytesBlobBlock, 0, PageSize)

Dim BlobPage As PageParams = ReadObjectPageDefinition(reader, BytesBlobBlock, PageSize)
BlobPage.BinaryData = ReadAllStoragePagesForObject(reader, BlobPage)

Dim BytesValTemp = GetCleanDataFromBlob(DataPos, DataSize, BlobPage.BinaryData)

If BytesValTemp.SequenceEqual(OldData) Then




Else
reader.Close()
Throw New System.Exception("Информация в БД была изменена другим процессом! Прочитайте список пользователей заново.")
End If

reader.Close()

End Sub


End Module
3 changes: 2 additions & 1 deletion PasswordChanger1C/Form1.vb
Original file line number Diff line number Diff line change
Expand Up @@ -441,13 +441,14 @@ Public Class MainForm

Dim NewHash = CommonModule.EncryptStringSHA1(NewPassword.Text.Trim)

Dim OldDataBinary = Row("DATA_BINARY")
Dim OldData = Row("DATA").ToString
Dim NewData = OldData.Replace(Row("UserPassHash"), """" + NewHash + """")
NewData = NewData.Replace(Row("UserPassHash2"), """" + NewHash + """")

Dim NewBytes = CommonModule.EncodePasswordStructure(NewData, Row("DATA_KEYSIZE"), Row("DATA_KEY"))

AccessFunctions.WritePasswordIntoInfoBaseIB(FileIB.Text, TableParams, DirectCast(Row("ID"), Byte()), NewBytes, Row("DATA_POS"), Row("DATA_SIZE"))
AccessFunctions.WritePasswordIntoInfoBaseIB(FileIB.Text, TableParams, DirectCast(Row("ID"), Byte()), OldDataBinary, NewBytes, Row("DATA_POS"), Row("DATA_SIZE"))

End If

Expand Down
10 changes: 5 additions & 5 deletions PasswordChanger1C/My Project/Application.Designer.vb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 13 additions & 12 deletions PasswordChanger1C/My Project/Resources.Designer.vb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

62 changes: 31 additions & 31 deletions PasswordChanger1C/My Project/Settings.Designer.vb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit c3fe113

Please sign in to comment.