Searching for free space fixed!

I can now continue with the attack expander.
This commit is contained in:
Gamer2020 2015-12-29 05:05:56 -05:00
parent a957dba765
commit 94046436e3
15 changed files with 135 additions and 100 deletions

Binary file not shown.

View File

@ -1,4 +1,6 @@
Imports System.IO
Option Strict Off
Option Explicit On
Imports System.IO
Public Class AttackExpander
Private Sub AttackExpander_Load(sender As Object, e As EventArgs) Handles MyBase.Load

View File

@ -16,7 +16,7 @@
<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
</dsig:Transforms>
<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
<dsig:DigestValue>XyOEDKFMxBvklN+6056G84y6/uo=</dsig:DigestValue>
<dsig:DigestValue>xCGc77xuhTzFkmBux90dKBsoxzs=</dsig:DigestValue>
</hash>
</dependentAssembly>
</dependency>

View File

@ -50,7 +50,7 @@
<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
</dsig:Transforms>
<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
<dsig:DigestValue>PAf6FxgFYUAixqkl7QKqzILPITA=</dsig:DigestValue>
<dsig:DigestValue>zfIfQA394oVQVjkALdzRdn72vio=</dsig:DigestValue>
</hash>
</dependentAssembly>
</dependency>

View File

@ -16,7 +16,7 @@
<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
</dsig:Transforms>
<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
<dsig:DigestValue>XyOEDKFMxBvklN+6056G84y6/uo=</dsig:DigestValue>
<dsig:DigestValue>xCGc77xuhTzFkmBux90dKBsoxzs=</dsig:DigestValue>
</hash>
</dependentAssembly>
</dependency>

View File

@ -50,7 +50,7 @@
<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
</dsig:Transforms>
<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
<dsig:DigestValue>PAf6FxgFYUAixqkl7QKqzILPITA=</dsig:DigestValue>
<dsig:DigestValue>zfIfQA394oVQVjkALdzRdn72vio=</dsig:DigestValue>
</hash>
</dependentAssembly>
</dependency>

View File

@ -82,7 +82,7 @@ Module mMain
End Function
Public Function MakeFreeSpaceString(NeededLength As Integer)
Public Function MakeFreeSpaceString(NeededLength As Integer, Optional NeedByteString As String = "FF")
Dim PrivLoopVar As Integer
Dim OutBuffThing As String = ""
@ -91,7 +91,7 @@ Module mMain
While (PrivLoopVar < NeededLength)
OutBuffThing = OutBuffThing & "FF"
OutBuffThing = OutBuffThing & NeedByteString
PrivLoopVar = PrivLoopVar + 1
End While

View File

@ -1,150 +1,155 @@
Option Explicit On
Option Strict Off
Option Explicit On
Imports VB = Microsoft.VisualBasic
Imports System.IO
Module modSearchFreeSpace
'06/22/2013 - This code has been ported to VB.Net by Gamer2020
' '06/22/2013 - This code has been ported to VB.Net by Gamer2020
' '12/29/2015 - It doesn't seem to be working. Code commented out and adding Jambo51's function.
' Copyright © 2009 HackMew
' ------------------------------
' Feel free to create derivate works from it, as long as you clearly give me credits of my code and
' make available the source code of derivative programs or programs where you used parts of my code.
' Redistribution is allowed at the same conditions.
' ' Copyright © 2009 HackMew
' ' ------------------------------
' ' Feel free to create derivate works from it, as long as you clearly give me credits of my code and
' ' make available the source code of derivative programs or programs where you used parts of my code.
' ' Redistribution is allowed at the same conditions.
'Private Const sMyName As String = "modSearchFreeSpace"
' 'Private Const sMyName As String = "modSearchFreeSpace"
'This function wasn't working so I made my own.
'Private Declare Sub RtlFillMemory Lib "kernel32" (ByVal pDest As Byte, ByVal nLen As Long, ByVal Fill As Byte)
' 'This function wasn't working so I made my own.
' 'Private Declare Sub RtlFillMemory Lib "kernel32" (ByVal pDest As Byte, ByVal nLen As Long, ByVal Fill As Byte)
Public Function SearchFreeSpace(ByVal FileName As String, ByVal FreeSpaceByte As Byte, ByVal NeededBytes As Long, Optional ByVal StartOffset As Long = 0&, Optional ByVal ChunkSize As Long = 65536, Optional ByVal Accuracy As Byte = 0) As Long
'Const sThis As String = "SearchFreeSpace"
Dim iFileNum As Long
Dim lFileLen As Long
Dim lOffset As Long
Dim lIncrement As Long
Dim bBuffer() As Byte
Dim bSearch() As Byte
Dim i As Long
Dim loopy As Integer
' Public Function SearchFreeSpace(ByVal FileName As String, ByVal FreeSpaceByte As Byte, ByVal NeededBytes As Long, Optional ByVal StartOffset As Long = 0&, Optional ByVal ChunkSize As Long = 65536, Optional ByVal Accuracy As Byte = 0) As Long
' 'Const sThis As String = "SearchFreeSpace"
' Dim iFileNum As Long
' Dim lFileLen As Long
' Dim lOffset As Long
' Dim lIncrement As Long
' Dim bBuffer() As Byte
' Dim bSearch() As Byte
' Dim i As Long
' Dim loopy As Integer
On Error GoTo LocalHandler
' On Error GoTo LocalHandler
' Check if NeededBytes and ChunkSize
' are higher than zero
If (NeededBytes + ChunkSize) Then
' ' Check if NeededBytes and ChunkSize
' ' are higher than zero
' If (NeededBytes + ChunkSize) Then
' Set the increment
lIncrement = ChunkSize \ (CLng(Accuracy) + 1&)
' ' Set the increment
' lIncrement = ChunkSize \ (CLng(Accuracy) + 1&)
' Allocate the buffer and the search pattern
ReDim bBuffer(ChunkSize - 1&)
ReDim bSearch(NeededBytes - 1&)
' ' Allocate the buffer and the search pattern
' ReDim bBuffer(ChunkSize - 1&)
' ReDim bSearch(NeededBytes - 1&)
' Fill the search pattern with the
' FreeSpaceByte when it's not 0
'This function wasn't working so I made my own.
' ' Fill the search pattern with the
' ' FreeSpaceByte when it's not 0
' 'This function wasn't working so I made my own.
'If FreeSpaceByte Then
'RtlFillMemory(bSearch(0), NeededBytes, FreeSpaceByte)
'End If
' 'If FreeSpaceByte Then
' 'RtlFillMemory(bSearch(0), NeededBytes, FreeSpaceByte)
' 'End If
loopy = 0
' loopy = 0
'just a simple loop to fill the buffer.
While loopy < NeededBytes
' 'just a simple loop to fill the buffer.
' While loopy < NeededBytes
bSearch(loopy) = bSearch(loopy) & FreeSpaceByte
' bSearch(loopy) = bSearch(loopy) & FreeSpaceByte
loopy = loopy + 1
' loopy = loopy + 1
End While
' End While
' Get the next free number
iFileNum = FreeFile()
' ' Get the next free number
' iFileNum = FreeFile()
' Open the file
'Open FileName For Binary As iFileNum
FileOpen(iFileNum, FileName, OpenMode.Binary)
' Get the file length
lFileLen = LOF(iFileNum)
' ' Open the file
' 'Open FileName For Binary As iFileNum
' FileOpen(iFileNum, FileName, OpenMode.Binary)
' ' Get the file length
' lFileLen = LOF(iFileNum)
' Ensure the file is not empty
If lFileLen Then
' ' Ensure the file is not empty
' If lFileLen Then
' Check if the StartOffset is valid
If (lFileLen - StartOffset) Then
' ' Check if the StartOffset is valid
' If (lFileLen - StartOffset) Then
' Loop through the file
For i = 0& To (lFileLen - StartOffset) \ ChunkSize
' ' Loop through the file
' For i = 0& To (lFileLen - StartOffset) \ ChunkSize
' Get a file chunk at the current offset
'Get #iFileNum, StartOffset + 1&, bBuffer
FileGet(iFileNum, bBuffer, StartOffset + 1&)
' ' Get a file chunk at the current offset
' 'Get #iFileNum, StartOffset + 1&, bBuffer
' FileGet(iFileNum, bBuffer, StartOffset + 1&)
' Search the needed space
'lOffset = InStrB(bBuffer, bSearch)
lOffset = InStr(bBuffer(0), bSearch(0))
' ' Search the needed space
' 'lOffset = InStrB(bBuffer, bSearch)
' lOffset = InStr(bBuffer(0), bSearch(0))
' Was there enough space?
If lOffset Then
' ' Was there enough space?
' If lOffset Then
' Yeah, stop searching
lOffset = lOffset + StartOffset - 1&
Exit For
' ' Yeah, stop searching
' lOffset = lOffset + StartOffset - 1&
' Exit For
End If
' End If
' Increment the offset
StartOffset = StartOffset + lIncrement
' ' Increment the offset
' StartOffset = StartOffset + lIncrement
Next i
' Next i
End If
' End If
End If
' End If
FileClose(iFileNum)
' FileClose(iFileNum)
' Make sure the offset isn't past the EOF
If lOffset < lFileLen Then
SearchFreeSpace = lOffset
End If
' ' Make sure the offset isn't past the EOF
' If lOffset < lFileLen Then
' SearchFreeSpace = lOffset
' End If
End If
Exit Function
' End If
' Exit Function
LocalHandler:
'LocalHandler:
'insert error handler here
' 'insert error handler here
'Select Case GlobalHandler(sThis, sMyName)
' Case vbRetry
' Resume
' Case vbAbort
' Quit()
' Case Else
' Resume Next
' End Select
' 'Select Case GlobalHandler(sThis, sMyName)
' ' Case vbRetry
' ' Resume
' ' Case vbAbort
' ' Quit()
' ' Case Else
' ' Resume Next
' ' End Select
End Function
' End Function
Public Function SearchFreeSpaceFourAligned(ByVal FileName As String, ByVal FreeSpaceByte As Byte, ByVal NeededBytes As Long, Optional ByVal StartOffset As Long = 0) As Long
Dim SearchIncrement As String
Dim CurSearchOffset As String
CurSearchOffset = Hex(SearchFreeSpace(FileName, FreeSpaceByte, NeededBytes, StartOffset, 100))
CurSearchOffset = Hex(FindFreeSpace(FileName, FreeSpaceByte, NeededBytes, StartOffset))
SearchIncrement = 1
While (((CurSearchOffset(CurSearchOffset.Length - 1)) <> "0") AndAlso ((CurSearchOffset(CurSearchOffset.Length - 1)) <> "4") AndAlso ((CurSearchOffset(CurSearchOffset.Length - 1)) <> "8") AndAlso ((CurSearchOffset(CurSearchOffset.Length - 1)) <> "C"))
CurSearchOffset = Hex(SearchFreeSpace(FileName, FreeSpaceByte, NeededBytes, (StartOffset) + SearchIncrement))
MsgBox(CInt("&H" & CurSearchOffset) + CInt(SearchIncrement))
CurSearchOffset = Hex(FindFreeSpace(FileName, FreeSpaceByte, NeededBytes, CInt("&H" & CurSearchOffset) + CInt(SearchIncrement)))
SearchIncrement = SearchIncrement + 1
@ -154,4 +159,32 @@ LocalHandler:
End Function
Private Function FindFreeSpace(selectedROMPath As String, freeSpaceByte As Byte, dataSize As Integer, startLocation As Integer) As Integer
Dim rom As Byte() = File.ReadAllBytes(selectedROMPath)
Dim spaceFound As Boolean = False
While Not spaceFound
For i As Integer = 0 To dataSize
If startLocation + dataSize <= rom.Length Then
If rom(startLocation + i) <> freeSpaceByte Then
Exit For
ElseIf i = dataSize Then
spaceFound = True
Exit For
End If
Else
spaceFound = True
'MessageBox.Show("No free space could be found in the alloted area. Try widening the search parameters.")
startLocation = 8388608
Exit For
End If
Next
If Not spaceFound Then
startLocation += 1
End If
End While
Return startLocation
End Function
End Module

View File

@ -16,7 +16,7 @@
<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
</dsig:Transforms>
<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
<dsig:DigestValue>XyOEDKFMxBvklN+6056G84y6/uo=</dsig:DigestValue>
<dsig:DigestValue>xCGc77xuhTzFkmBux90dKBsoxzs=</dsig:DigestValue>
</hash>
</dependentAssembly>
</dependency>

View File

@ -50,7 +50,7 @@
<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
</dsig:Transforms>
<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
<dsig:DigestValue>PAf6FxgFYUAixqkl7QKqzILPITA=</dsig:DigestValue>
<dsig:DigestValue>zfIfQA394oVQVjkALdzRdn72vio=</dsig:DigestValue>
</hash>
</dependentAssembly>
</dependency>