Jump to content

How to search hex sequence containing unknown sequence? - (Moved)


Recommended Posts

How to search hex sequence containing unknown sequence?

For Example:

11223344 55667788 XXXXXXXX 99AABBCC DDEEFF00

XXXXXXXX = Hex Sequence that always change

How to search 11223344 55667788 XXXXXXXX 99AABBCC DDEEFF00 without specifying XXXXXXXX?

 

Thank You

Link to comment
Share on other sites

  • Moderators

Moved to the appropriate AutoIt General Help and Support forum, as the Developer General Discussion forum very clearly states:

Quote

General development and scripting discussions.


Do not create AutoIt-related topics here, use the AutoIt General Help and Support or AutoIt Technical Discussion forums.

Moderation Team

Edited by JLogan3o13

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

  • Moderators

The topic has been moved to a more appropriate spot. @HezzelQuartz, as Andreik mentions, you haven't provided enough information. You state the section will always change, will it always be in the same place (third octet in your example)? Or will that change too? Are you looking to validate that section against some other data, or just return what that section contains? Help us help you ;)

 

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

@Andreik

 

But, in this case, I don't know what is XXXXXXXX and cannot determine what is XXXXXXXX

So, I need the search to find the first, second, fourth, fifth octet in order, whatever the third octet (XXXXXXXX) is not a problem

For Example, the search can find these two sequence below

11223344 55667788 "66AA66BB" 99AABBCC DDEEFF00

11223344 55667788 "99CCAA00" 99AABBCC DDEEFF00

 

Sorry if my explanation not clear enough

Link to comment
Share on other sites

29 minutes ago, HezzelQuartz said:

I need the search to find the first, second, fourth, fifth octet in order, whatever the third octet (XXXXXXXX) is

This question implies that you already know the content of the first, second, fourth, fifth octets, and that you want to get the whole sequence of 5 octets
So maybe this ?

#Include <Array.au3>

$s = "ABCDEFAB 11223344 55667788 66AA66BB 99AABBCC DDEEFF00 12345678" & @crlf & _ 
    "12345678 11223344 55667788 99CCAA00 99AABBCC DDEEFF00 ABCDEFAB"

$res = StringRegExp($s, '11223344 55667788 [[:xdigit:]]{8} 99AABBCC DDEEFF00', 3)
_ArrayDisplay($res)

 

Link to comment
Share on other sites

56 minutes ago, HezzelQuartz said:

@Andreik

 

But, in this case, I don't know what is XXXXXXXX and cannot determine what is XXXXXXXX

So, I need the search to find the first, second, fourth, fifth octet in order, whatever the third octet (XXXXXXXX) is not a problem

For Example, the search can find these two sequence below

11223344 55667788 "66AA66BB" 99AABBCC DDEEFF00

11223344 55667788 "99CCAA00" 99AABBCC DDEEFF00

 

Sorry if my explanation not clear enough

You don't have to know anything, in the matches array you will have all sequences indexed. Pick the 3rd sequence or whatever.

Link to comment
Share on other sites

  • 1 month later...

@Andreik @mikell

Wooow, I'm really thankful for all your help.


I have one more question please.

What if I need to know the sequence between two first octet and two last octet?

"11223344 55667788 66AA66BB 99AABBCC DDEEFF00"

"11223344 55667788 4455AACC DDEEBBDD 99AABBCC DDEEFF00"

 

I want to know 66AA66BB in the first example and 4455AACC DDEEBBDD in the second example.

Link to comment
Share on other sites

You can write a more specialized function that will allow you to trim a certain number of octets from both sides. Here is an example:

$sData = '11223344 55667788 66AA66BB 99AABBCC DDEEFF00'
ConsoleWrite(TrimDW($sData, 2, 2) & @CRLF)

$sData = '11223344 55667788 4455AACC DDEEBBDD 99AABBCC DDEEFF00'
ConsoleWrite(TrimDW($sData, 2, 2) & @CRLF)

Func TrimDW($sData, $iLeft = 0, $iRight = 0)
    Local $sResult
    Local $aMatches = StringRegExp($sData, '([0-9a-fA-F]{8})', 3)
    If Not IsArray($aMatches) Then Return SetError(1, 0, Null)
    Local $iMatches = UBound($aMatches)
    If $iMatches < $iLeft Then Return SetError(2, 0, Null)
    If $iMatches < $iRight Then Return SetError(3, 0, Null)
    If $iMatches < $iLeft + $iRight Then Return SetError(4, 0, Null)
    For $Index = $iLeft To $iMatches - $iRight - 1
        $sResult &= $aMatches[$Index] & ' '
    Next
    Return StringTrimRight($sResult, 1)
EndFunc

or if you always want to trim 2 groups from left and 2 from right you can use this

$sData = '11223344 55667788 66AA66BB 99AABBCC DDEEFF00'
$sNew = StringRegExpReplace($sData, '^(([0-9a-fA-F]{8} )){2}|(( [0-9a-fA-F]{8}){2})$', '')
ConsoleWrite($sNew & @CRLF)

$sData = '11223344 55667788 4455AACC DDEEBBDD 99AABBCC DDEEFF00'
$sNew = StringRegExpReplace($sData, '^(([0-9a-fA-F]{8} )){2}|(( [0-9a-fA-F]{8}){2})$', '')
ConsoleWrite($sNew & @CRLF)

BTW an octet it's a single byte and you want to trim 8 bytes from each side in the form of 2 double word.

Edited by Andreik
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...