HezzelQuartz Posted October 31 Share Posted October 31 (edited) If I have a hex file: FF 43 01 D1 FE 0B 00 F9 F8 5F 02 A9 F6 57 03 A9 F4 4F 04 A9 58 D0 3B D5 F3 03 08 AA 08 17 40 F9 12 12 12 12 F5 03 00 AA E8 07 00 F9 43 FE FF 97 9F 06 00 71 F6 03 00 2A AB 00 00 54 How can I get a list of array start from 43? 43 01 D1 FE ... 00 00 54 I tried, something like this $hFile1 = FileOpen(@ScriptDir & '\example.so', 16) $bRead1 = FileRead($hFile1) $aFile1 = StringRegExp($bRead1, '[[:xdigit:]]{2}', $STR_REGEXPARRAYGLOBALMATCH, 3) _ArrayDisplay($aFile1) FileClose($hFile1) But it always start from FF, not 43 Can anyone please give solution or at least any clues for me? =================================================================================================== I have another question 1. Which one is right for my code above [[:xdigit:]]{2} or ([[:xdigit:]]{2})? 2. Is there any better or faster solution to get a list of array other than using StringRegExp? Thank You Edited October 31 by HezzelQuartz Link to comment Share on other sites More sharing options...
pixelsearch Posted October 31 Share Posted October 31 T 3 hours ago, HezzelQuartz said: But it always start from FF, not 43 This is because the binary string returned by FileRead starts with "0x" so f you want to start from 43, then you should indicate 5 as offset (last parameter in StringRegExp) to bypass "0xFF" HezzelQuartz 1 Link to comment Share on other sites More sharing options...
HezzelQuartz Posted October 31 Author Share Posted October 31 (edited) 24 minutes ago, pixelsearch said: T This is because the binary string returned by FileRead starts with "0x" so f you want to start from 43, then you should indicate 5 as offset (last parameter in StringRegExp) to bypass "0xFF" Thank You It worked Is there any better or faster solution to get a list of array other than using StringRegExp above? how can I get the size or length of that array list? Should I use Ubound? Edited October 31 by HezzelQuartz Link to comment Share on other sites More sharing options...
pixelsearch Posted October 31 Share Posted October 31 (edited) 28 minutes ago, HezzelQuartz said: Is there any better or faster solution to get a list of array other than using StringRegExp above? I don't think so. You can't use StringSplit as there are no delimiters. I just tested your script with a binary file of 116KB (237570 bytes length) and the RegExp part was immediate ("There" will be displayed immediately after "Here" in the script below) : ConsoleWrite("Here" & @crlf) $aFile1 = StringRegExp($bRead1, '[[:xdigit:]]{2}', $STR_REGEXPARRAYGLOBALMATCH, 5) ConsoleWrite("There" & @crlf) ConsoleWrite(Ubound($aFile1) & @crlf) ; 118783 rows The ArrayDisplay part will take much longer with 118783 rows to display. 3 hours ago, HezzelQuartz said: Which one is right for my code above [[:xdigit:]]{2} or ([[:xdigit:]]{2})? I think you don't need a group (...) in your case, this is what I read on a website right now : What is the purpose of regex capture groups? Capturing groups allow you to treat a part of your regex pattern as a single unit. This is especially useful when you want to apply quantifiers or modifiers to multiple characters or subpatterns. For example, (abc)+ matches one or more repetitions of "abc" as a whole [...] Edited October 31 by pixelsearch Link to comment Share on other sites More sharing options...
HezzelQuartz Posted October 31 Author Share Posted October 31 (edited) 1 hour ago, pixelsearch said: I don't think so. You can't use StringSplit as there are no delimiters. I just tested your script with a binary file of 116KB (237570 bytes length) and the RegExp part was immediate ("There" will be displayed immediately after "Here" in the script below) : ConsoleWrite("Here" & @crlf) $aFile1 = StringRegExp($bRead1, '[[:xdigit:]]{2}', $STR_REGEXPARRAYGLOBALMATCH, 5) ConsoleWrite("There" & @crlf) ConsoleWrite(Ubound($aFile1) & @crlf) ; 118783 rows The ArrayDisplay part will take much longer with 118783 rows to display. I think you don't need a group (...) in your case, this is what I read on a website right now : What is the purpose of regex capture groups? Capturing groups allow you to treat a part of your regex pattern as a single unit. This is especially useful when you want to apply quantifiers or modifiers to multiple characters or subpatterns. For example, (abc)+ matches one or more repetitions of "abc" as a whole [...] It seems that my code doesn't work to 137,496 KB file size.... When I run it, nothing happened for a very long time, and autoit logo suddenly disappeared Did I do something wrong with the code? ============================================================================================================ When I tried to run my code to 16,000++ KB file size It worked well When I tried to run my code to 49,000++ KB file size Error appear: error allocating memory Edited October 31 by HezzelQuartz Link to comment Share on other sites More sharing options...
pixelsearch Posted October 31 Share Posted October 31 (edited) 1 hour ago, HezzelQuartz said: When I tried to run my code to 16,000++ KB file size It worked well This is because the maximum number of elements for an array is 16,777,216 (help file, AutoIt3 Limits/defaults) When you divide that number of 16,777,216 by 1024 bytes, it gives you the maximal size of your file in KB, i.e. 16,384 KB, that's why your test on 16,000++ KB file size worked, because each byte will become a row in the array and you're still under the limit of 16,777,216 elements Edited October 31 by pixelsearch Link to comment Share on other sites More sharing options...
HezzelQuartz Posted October 31 Author Share Posted October 31 (edited) 2 hours ago, pixelsearch said: This is because the maximum number of elements for an array is 16,777,216 (help file, AutoIt3 Limits/defaults) When you divide that number of 16,777,216 by 1024 bytes, it gives you the maximal size of your file in KB, i.e. 16,384 KB, that's why your test on 16,000++ KB file size worked, because each byte will become a row in the array and you're still under the limit of 16,777,216 elements Is there any way to increase the limit? Actually, I want to compare two hex file by splitting every byte into array, then compare every array This is my code below $hFile1 = FileOpen(@ScriptDir & '\example1.so', 16) $bRead1 = FileRead($hFile1) $hFile2 = FileOpen(@ScriptDir & '\example2.so', 16) $bRead2 = FileRead($hFile2) $aFile1 = StringRegExp($bRead1, '[[:xdigit:]]{2}', $STR_REGEXPARRAYGLOBALMATCH, 1) $aFile2 = StringRegExp($bRead2, '[[:xdigit:]]{2}', $STR_REGEXPARRAYGLOBALMATCH, 1) For $i = 1 To UBound($aFile1, $UBOUND_ROWS)-1 If $aFile1[$i] <> $aFile2[$i] Then If Mod($i, 4) = 0 Then FileWrite(@ScriptDir & '\' & 'Compare Result.txt', $aFile1[$i] & ' ' & $aFile1[$i+1] & ' ' & $aFile1[$i+2] & ' ' & $aFile1[$i+3] & ' ' & $aFile2[$i] & ' ' & $aFile2[$i+1] & ' ' & $aFile2[$i+2] & ' ' & $aFile2[$i+3] & @CRLF) $i = $i + 4 ElseIf Mod($i, 4) = 1 Then FileWrite(@ScriptDir & '\' & 'Compare Result.txt', $aFile1[$i-1] & ' ' & $aFile1[$i] & ' ' & $aFile1[$i+1] & ' ' & $aFile1[$i+2] & ' ' & $aFile2[$i-1] & ' ' & $aFile2[$i] & ' ' & $aFile2[$i+1] & ' ' & $aFile2[$i+2] & @CRLF) $i = $i + 3 ElseIf Mod($i, 4) = 2 Then FileWrite(@ScriptDir & '\' & 'Compare Result.txt', $aFile1[$i-2] & ' ' & $aFile1[$i-1] & ' ' & $aFile1[$i] & ' ' & $aFile1[$i+1] & ' ' & $aFile2[$i-2] & ' ' & $aFile2[$i-1] & ' ' & $aFile2[$i] & ' ' & $aFile2[$i+1] & @CRLF) $i = $i + 2 ElseIf Mod($i, 4) = 3 Then FileWrite(@ScriptDir & '\' & 'Compare Result.txt', $aFile1[$i-3] & ' ' & $aFile1[$i-2] & ' ' & $aFile1[$i-1] & ' ' & $aFile1[$i] & ' ' & $aFile2[$i-3] & ' ' & $aFile2[$i-2] & ' ' & $aFile2[$i-1] & ' ' & $aFile2[$i] & @CRLF) $i = $i + 1 EndIf ElseIf $aFile1[$i] = $aFile2[$i] Then ContinueLoop EndIf Next FileClose($hFile1) FileClose($hFile2) Or, Is there any way I can split file read every 16,000 KB? Or can I read from 16,001 KB to 32,000 KB? Edited October 31 by HezzelQuartz Link to comment Share on other sites More sharing options...
Nine Posted October 31 Share Posted October 31 (edited) If I correctly understand, you want to compare 2 files of same length starting at byte 2. So you could try this : $hFile1 = FileOpen(@ScriptDir & '\example1.so', 16) $bRead1 = FileRead($hFile1) $hFile2 = FileOpen(@ScriptDir & '\example2.so', 16) $bRead2 = FileRead($hFile2) FileClose($hFile1) FileClose($hFile2) Local $dMid1, $dMid2 For $i = 2 To BinaryLen($bRead1) If BinaryMid($bRead1, $i, 1) <> BinaryMid($bRead2, $i, 1) Then $iMod = Mod($i, 4) $dMid1 = BinaryMid($bRead1, $i - $iMod, 4) $dMid2 = BinaryMid($bRead2, $i - $iMod, 4) $i = $i + 4 - $iMod ConsoleWrite($dMid1 & "/" & $dMid2 & @CRLF) EndIf Next Works for me with my example files. ps. I'll let you format the output as you want Edited October 31 by Nine typo “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
HezzelQuartz Posted October 31 Author Share Posted October 31 (edited) 31 minutes ago, Nine said: If I correctly understand, you want to compare 2 files of same length starting at byte 2. So you could try this : $hFile1 = FileOpen(@ScriptDir & '\example1.so', 16) $bRead1 = FileRead($hFile1) $hFile2 = FileOpen(@ScriptDir & '\example2.so', 16) $bRead2 = FileRead($hFile2) FileClose($hFile1) FileClose($hFile2) Local $dMid1, $dMid2 For $i = 2 To BinaryLen($bRead1) If BinaryMid($bRead1, $i, 1) <> BinaryMid($bRead2, $i, 1) Then $iMod = Mod($i, 4) $dMid1 = BinaryMid($bRead1, $i - $iMod, 4) $dMid2 = BinaryMid($bRead2, $i - $iMod, 4) $i = $i + 4 - $iMod ConsoleWrite($dMid1 & "/" & $dMid2 & @CRLF) EndIf Next Works for me with my example files. ps. I'll let you format the output as you want does it work with very big file? the size of file I want to compare is 130,000++ KB Edited October 31 by HezzelQuartz Link to comment Share on other sites More sharing options...
Nine Posted October 31 Share Posted October 31 (edited) Should, what about you try it. MAX_BINARYSIZE = 2,147,483,647 : Maximum bytes of binary data. Edited October 31 by Nine HezzelQuartz 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
HezzelQuartz Posted October 31 Author Share Posted October 31 1 minute ago, Nine said: Should, what about you try it. MAX_BINARYSIZE = 2,147,483,647 : Maximum bytes of binary data. I'm trying to run and learning this code and function now Thank You for this code ============================================================================================================================ Btw, Is there any way I can change the limit of autoit? I mean: "AutoIt3 Limits/defaults" Sorry for my noob stupid question Link to comment Share on other sites More sharing options...
Nine Posted October 31 Share Posted October 31 (edited) Nope. I mean not those size max limits... Edited October 31 by Nine “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Nine Posted October 31 Share Posted October 31 If you want it extremely fast, I have an ASM program written in AutoIt that could perform it in about 1 sec. LMK. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
HezzelQuartz Posted October 31 Author Share Posted October 31 28 minutes ago, Nine said: If you want it extremely fast, I have an ASM program written in AutoIt that could perform it in about 1 sec. LMK. Yes, I really want it. Link to comment Share on other sites More sharing options...
Nine Posted October 31 Share Posted October 31 (edited) Ok. This is the unmodified version I have (it starts at first byte). Try it and if it works correctly, then you can adapt it to your needs (I'll help if needed). expandcollapse popup; Assembly - Assembler - Comparaison #include <WinAPIDiag.au3> Opt("MustDeclareVars", True) Local $tFile1 = ReadBinaryFile('c:\apps\temp\example1.so') Local $tFile2 = ReadBinaryFile('c:\apps\temp\example2.so') Local $hInit = TimerInit() Local $tResult = CompareData($tFile1, $tFile2, 10000) ; make it large enough to receive results If @error Then Exit MsgBox($MB_OK, "Error", @error = 1 ? "Size not equal" : "Increase buffer size") Local $nResult = @extended, $pResult = DllStructGetPtr($tResult) ConsoleWrite("Time: " & TimerDiff($hInit) & " ms" & @CRLF) Local $tDiff For $i = 1 To $nResult $tDiff = DllStructCreate("align 1;byte b1;byte b2;dword idx;", $pResult) ConsoleWrite(Hex($tDiff.b1, 2) & @TAB & Hex($tDiff.b2, 2) & @TAB & Hex($tDiff.idx, 8) & @CRLF) $pResult += 6 Next Func CompareData(Const ByRef $tFile1, Const ByRef $tFile2, $iSize) If DllStructGetSize($tFile1) <> DllStructGetSize($tFile2) Then Return SetError(1) Local $tResult = DllStructCreate("byte data[" & $iSize & "]") Local $sCode = '0x8B7424048B7C24088B4C240C8B54241031DB8A068A2738E07412836C24140678158802886201895A0283C206434647E2E189D0C2140031C083E801C21400' Local $dCode = Binary($sCode) Local $iCodeSize = BinaryLen($dCode) Local $tBuffer = DllStructCreate('byte Code[' & $iCodeSize & ']') DllStructSetData($tBuffer, 'Code', $dCode) Local $aCall = DllCallAddress('int', DllStructGetPtr($tBuffer), 'ptr', DllStructGetPtr($tFile1), 'ptr', DllStructGetPtr($tFile2), _ 'int', DllStructGetSize($tFile1), 'ptr', DllStructGetPtr($tResult), 'int', $iSize) If $aCall[0] = -1 Then Return SetError(2) Local $iResult = ($aCall[0] - DllStructGetPtr($tResult)) / 6 Return SetExtended($iResult, $tResult) EndFunc ;==>CompareData Func ReadBinaryFile($sPath) Local $iSize = FileGetSize($sPath) Local $tFile = DllStructCreate("byte Data[" & $iSize & "]") Local $hFile = FileOpen($sPath, $FO_BINARY) $tFile.Data = FileRead($hFile) FileClose($hFile) Return $tFile EndFunc ;==>ReadBinaryFile #cs mov esi,DWORD PTR [esp+0x04] mov edi,DWORD PTR [esp+0x08] mov ecx,DWORD PTR [esp+0x0c] mov edx,DWORD PTR [esp+0x10] xor ebx,ebx l1: mov al,BYTE PTR [esi] mov ah,BYTE PTR [edi] cmp al,ah je l2 sub DWORD PTR [esp+0x14],6 js l3 mov BYTE PTR [edx],al mov BYTE PTR [edx+1],ah mov DWORD PTR [edx+2],ebx add edx,6 l2: inc ebx inc esi inc edi loop l1 mov eax,edx ret 20 l3: xor eax,eax sub eax,1 ret 20 #ce ps. it runs only x86 Edited October 31 by Nine pixelsearch and HezzelQuartz 1 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
HezzelQuartz Posted October 31 Author Share Posted October 31 @Nine Thank You I will try, read and learn it thoroughly Link to comment Share on other sites More sharing options...
HezzelQuartz Posted November 1 Author Share Posted November 1 (edited) 19 hours ago, Nine said: If I correctly understand, you want to compare 2 files of same length starting at byte 2. So you could try this : $hFile1 = FileOpen(@ScriptDir & '\example1.so', 16) $bRead1 = FileRead($hFile1) $hFile2 = FileOpen(@ScriptDir & '\example2.so', 16) $bRead2 = FileRead($hFile2) FileClose($hFile1) FileClose($hFile2) Local $dMid1, $dMid2 For $i = 2 To BinaryLen($bRead1) If BinaryMid($bRead1, $i, 1) <> BinaryMid($bRead2, $i, 1) Then $iMod = Mod($i, 4) $dMid1 = BinaryMid($bRead1, $i - $iMod, 4) $dMid2 = BinaryMid($bRead2, $i - $iMod, 4) $i = $i + 4 - $iMod ConsoleWrite($dMid1 & "/" & $dMid2 & @CRLF) EndIf Next Works for me with my example files. ps. I'll let you format the output as you want I first learn your code above, when I tried to run this code below (I modify just a bit) $hFile1 = FileOpen(@ScriptDir & '\example1.so', 16) $bRead1 = FileRead($hFile1) $hFile2 = FileOpen(@ScriptDir & '\example2.so', 16) $bRead2 = FileRead($hFile2) For $i = 1 To BinaryLen($bRead1) If BinaryMid($bRead1, $i, 1) <> BinaryMid($bRead2, $i, 1) Then $iMod = Mod($i-1, 4) $bMid1 = BinaryMid($bRead1, $i - $iMod, 4) $bMid2 = BinaryMid($bRead2, $i - $iMod, 4) FileWrite(@ScriptDir & '\' & 'CompareResult.txt', StringTrimLeft($bMid1, 2) & ' ' & StringTrimLeft($bMid2, 2) & @CRLF) $i = $i + 4 - $iMod ElseIf BinaryMid($bRead1, $i, 1) = BinaryMid($bRead2, $i, 1) Then ContinueLoop EndIf If Mod($i, 1000) = 0 Then MsgBox($MB_SYSTEMMODAL, "Title", "1000 Done") EndIf Next FileClose($hFile1) FileClose($hFile2) It works well when I compare 1 KB file But nothing happened when I compare 16 KB file I also tried to run this code below $hFile1 = FileOpen(@ScriptDir & '\example1.so', 16) $bRead1 = FileRead($hFile1) $hFile2 = FileOpen(@ScriptDir & '\example2.so', 16) $bRead2 = FileRead($hFile2) FileClose($hFile1) FileClose($hFile2) Local $dMid1, $dMid2 For $i = 2 To BinaryLen($bRead1) If BinaryMid($bRead1, $i, 1) <> BinaryMid($bRead2, $i, 1) Then $iMod = Mod($i, 4) $dMid1 = BinaryMid($bRead1, $i - $iMod, 4) $dMid2 = BinaryMid($bRead2, $i - $iMod, 4) $i = $i + 4 - $iMod FileWrite(@ScriptDir & '\' & 'CompareResult.txt', $dMid1 & "/" & $dMid2 & @CRLF) EndIf Next It also works well when I compare 1 KB file But alsonothing happened when I compare 16 KB file Did I do something wrong? Edited November 1 by HezzelQuartz Link to comment Share on other sites More sharing options...
Nine Posted November 1 Share Posted November 1 (edited) Second script looks good. Put some log (ConsoleWrite) to see the evolution of the loop. If you can, post here the 2 files you are comparing and not working. I'll take a look. It seems it is coming from a larger script (that is probably the problem). Try running it simple (as is) first, make it work, then move the code to your final script. Made a new script to create large files and compare them. It works very well all size... expandcollapse popupFileDelete(@ScriptDir & '\example1.so') FileDelete(@ScriptDir & '\example2.so') GenerateFile(@ScriptDir & '\example1.so', 128000) FileCopy(@ScriptDir & '\example1.so', @ScriptDir & '\example2.so') ModifyFile(@ScriptDir & '\example2.so') Local $hFile1 = FileOpen(@ScriptDir & '\example1.so', 16) Local $bRead1 = FileRead($hFile1) Local $hFile2 = FileOpen(@ScriptDir & '\example2.so', 16) Local $bRead2 = FileRead($hFile2) FileClose($hFile1) FileClose($hFile2) Local $dMid1, $dMid2, $iMod For $i = 2 To BinaryLen($bRead1) If BinaryMid($bRead1, $i, 1) <> BinaryMid($bRead2, $i, 1) Then $iMod = Mod($i, 4) $dMid1 = BinaryMid($bRead1, $i - $iMod, 4) $dMid2 = BinaryMid($bRead2, $i - $iMod, 4) ConsoleWrite(StringRegExpReplace($dMid1, ".{2}(.{2})(.{2})(.{2})(.{2})", "\1 \2 \3 \4") & " / " & StringRegExpReplace($dMid2, ".{2}(.{2})(.{2})(.{2})(.{2})", "\1 \2 \3 \4") & @CRLF) $i = $i + 4 - $iMod EndIf Next Func GenerateFile($sFile, $iCount) Local $sText For $i = 1 To $iCount $sText &= Chr(Random(33, 122, 1)) Next FileWrite($sFile, $sText) EndFunc Func ModifyFile($sFile) Local $sText = FileRead($sFile), $iIdx For $i = 1 To 5 $iIdx = Random(5, StringLen($sText) - 5, 1) $sText = StringLeft($sText, $iIdx - 1) & " " & StringRight($sText, StringLen($sText) - $iIdx) Next FileDelete($sFile) FileWrite($sFile, $sText) EndFunc Edited November 1 by Nine “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
HezzelQuartz Posted November 2 Author Share Posted November 2 (edited) 22 hours ago, Nine said: Second script looks good. Put some log (ConsoleWrite) to see the evolution of the loop. If you can, post here the 2 files you are comparing and not working. I'll take a look. It seems it is coming from a larger script (that is probably the problem). Try running it simple (as is) first, make it work, then move the code to your final script. Made a new script to create large files and compare them. It works very well all size... expandcollapse popupFileDelete(@ScriptDir & '\example1.so') FileDelete(@ScriptDir & '\example2.so') GenerateFile(@ScriptDir & '\example1.so', 128000) FileCopy(@ScriptDir & '\example1.so', @ScriptDir & '\example2.so') ModifyFile(@ScriptDir & '\example2.so') Local $hFile1 = FileOpen(@ScriptDir & '\example1.so', 16) Local $bRead1 = FileRead($hFile1) Local $hFile2 = FileOpen(@ScriptDir & '\example2.so', 16) Local $bRead2 = FileRead($hFile2) FileClose($hFile1) FileClose($hFile2) Local $dMid1, $dMid2, $iMod For $i = 2 To BinaryLen($bRead1) If BinaryMid($bRead1, $i, 1) <> BinaryMid($bRead2, $i, 1) Then $iMod = Mod($i, 4) $dMid1 = BinaryMid($bRead1, $i - $iMod, 4) $dMid2 = BinaryMid($bRead2, $i - $iMod, 4) ConsoleWrite(StringRegExpReplace($dMid1, ".{2}(.{2})(.{2})(.{2})(.{2})", "\1 \2 \3 \4") & " / " & StringRegExpReplace($dMid2, ".{2}(.{2})(.{2})(.{2})(.{2})", "\1 \2 \3 \4") & @CRLF) $i = $i + 4 - $iMod EndIf Next Func GenerateFile($sFile, $iCount) Local $sText For $i = 1 To $iCount $sText &= Chr(Random(33, 122, 1)) Next FileWrite($sFile, $sText) EndFunc Func ModifyFile($sFile) Local $sText = FileRead($sFile), $iIdx For $i = 1 To 5 $iIdx = Random(5, StringLen($sText) - 5, 1) $sText = StringLeft($sText, $iIdx - 1) & " " & StringRight($sText, StringLen($sText) - $iIdx) Next FileDelete($sFile) FileWrite($sFile, $sText) EndFunc I'd like to send you the 2 example file I'm trying to compare. But, How can I send it here? Is there any way I can send you the file? ==================================================================================== I tried to do consolewrite and test run inside scite when I compare two small file, it showed normally when I compare two big file, no error showed but also no result showed ==================================================================================== Is there any way I can split read file? I mean, If a file is 48,000 KB Is there any way I can do: fileread1 0 - 16,000 KB fileread2 16,001 - 32,000 KB fileread3 32,001 - 48,000 KB Edited November 2 by HezzelQuartz Link to comment Share on other sites More sharing options...
Nine Posted November 2 Share Posted November 2 (edited) It will be terribly long to use my first script to compare such large files (48MB). It will take hours. I strongly suggest that you use my second script written in ASM. If you do not like it, use some command line comparaison program (e.g. fc.exe). In order to share so big files, you will need to save it in the cloud somewhere and give me the links to them. Here for the fun of it : #include <Constants.au3> #include <Array.au3> Local $sFile1 = @ScriptDir & '\example1.so', $sFile2 = @ScriptDir & '\example2.so' Local $hFile1 = FileOpen($sFile1, 16) Local $bRead1 = FileRead($hFile1) Local $hFile2 = FileOpen($sFile2, 16) Local $bRead2 = FileRead($hFile2) FileClose($hFile1) FileClose($hFile2) Local $iPID = Run("fc /B " & $sFile1 & " " & $sFile2, "", @SW_HIDE, $STDERR_MERGED + $STDIN_CHILD) ProcessWaitClose($iPID) Local $sResult = StdoutRead($iPID) ConsoleWrite($sResult & @CRLF) Local $aList = StringRegExp($sResult, "(?m)^([0-9A-F]{8}): ([0-9A-F]{2}) ([0-9A-F]{2})$", 3) _ArrayDisplay($aList) Local $iPos, $iMod, $dMid1, $dMid2 For $i = 0 To UBound($aList) - 1 Step 3 $iPos = Dec($aList[$i]) $iMod = Mod($iPos, 4) $dMid1 = BinaryMid($bRead1, $iPos - $iMod, 4) $dMid2 = BinaryMid($bRead2, $iPos - $iMod, 4) ConsoleWrite(StringRegExpReplace($dMid1, ".{2}(.{2})(.{2})(.{2})(.{2})", "\1 \2 \3 \4") & " / " & StringRegExpReplace($dMid2, ".{2}(.{2})(.{2})(.{2})(.{2})", "\1 \2 \3 \4") & @CRLF) Next ps. important note : both (asm and fc) scripts start at 1st byte (0-based) Edited November 2 by Nine script and note “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now