Detecting an arbitrary string of bytes at a known offset?

I need to use the content scanning feature to identify an arbitrary string of bytes. In particular, I need to identify a certain string of 768 bytes (binary stuff, not text), at a known offset within an attachment file of a specific type. I'm sorry I can't provide details such as exactly what attachment type and where within the file the 768 bytes are found, but that information is confidential and I am not at liberty to reveal it here. Expressed in pseudo-code, I need something like this:
if the attachment type is "xxxxxx/xxxx"
and bytes N:N+767 of the attachment match the binary string "..."
then act on this message
The attachment type is one that requires base64 encoding, and that is frustrating me. I could live with matching on the base64-encoded data by looking for a certain 13 consecutive lines, even though that's not quite as accurate because it does not take the offset into account (the signature is unique enough that this is acceptable). However, it appears that AsyncOS decodes base64 before doing content scanning.
Given my reading of the AsyncOS documentation, I don't think this is possible, but I'd like to be wrong.
Thanks,

No, I understand how to access the bytes one at a time, but I want to access the array of bytes from address 1948 onwards. I actually managed this with a string constructor (since it is a string i'm trying to get at), but there are probably other ways.

Similar Messages

  • How to get a string or byte array representation of an Image/BufferedImage?

    I have a java.awt.Image object that I want to transfer to a server application (.NET) through a http post request.
    To do that I would like to encode the Image to jpeg format and convert it to a string or byte array to be able to send it in a way that the receiver application (.NET) could handle. So, I've tried to do like this.
    private void send(Image image) {
        int width = image.getWidth(null);
        int height = image.getHeight(null);
        try {
            BufferedImage buffImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
            ImageIcon imageIcon = new ImageIcon(image);
            ImageObserver observer = imageIcon.getImageObserver();
            buffImage.getGraphics().setColor(new Color(255, 255, 255));
            buffImage.getGraphics().fillRect(0, 0, width, height);
            buffImage.getGraphics().drawImage(imageIcon.getImage(), 0, 0, observer);
            ByteArrayOutputStream stream = new ByteArrayOutputStream();
            JPEGImageEncoder jpeg = JPEGCodec.createJPEGEncoder(stream);
            jpeg.encode(buffImage);
            URL url = new URL(/* my url... */);
            URLConnection connection = url.openConnection();
            String boundary = "--------" + Long.toHexString(System.currentTimeMillis());
            connection.setRequestProperty("method", "POST");
            connection.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundary);
            String output = "--" + boundary + "\r\n"
                          + "Content-Disposition: form-data; name=\"myImage\"; filename=\"myFilename.jpg\"\r\n"
                          + "Content-Type: image/jpeg\r\n"
                          + "Content-Transfer-Encoding: base64\r\n\r\n"
                          + new String(stream.toByteArray())
                          + "\r\n--" + boundary + "--\r\n";
            connection.setDoOutput(true);
            connection.getOutputStream().write(output.getBytes());
            connection.connect();
        } catch {
    }This code works, but the image I get when I save it from the receiver application is distorted. The width and height is correct, but the content and colors are really weird. I tried to set different image types (first line inside the try-block), and this gave me different distorsions, but no image type gave me the correct image.
    Maybe I should say that I can display the original Image object on screen correctly.
    I also realized that the Image object is an instance of BufferedImage, so I thought I could skip the first six lines inside the try-block, but that doesn't help. This way I don't have to set the image type in the constructor, but the result still is color distorted.
    Any ideas on how to get from an Image/BufferedImage to a string or byte array representation of the image in jpeg format?

    Here you go:
      private static void send(BufferedImage image) throws Exception
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        ImageIO.write(image, "jpeg", byteArrayOutputStream);
        byte[] imageByteArray = byteArrayOutputStream.toByteArray();
        URL url = new URL("http://<host>:<port>");
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setDoOutput(true);
        connection.setRequestMethod("POST");
        OutputStream outputStream = connection.getOutputStream();
        outputStream.write(imageByteArray, 0, imageByteArray.length);
        outputStream.close();
        connection.connect();
        // alternative to connect is to get & close the input stream
        // connection.getInputStream().close();
      }

  • Conversion of String to Bytes and Length Calculation

    hi,
    How can I convert
    String to Bytes
    Bytes to String
    int to Bytes
    Bytes to int
    & int to String
    And I have to calculate the Length in Bytes of a String and int.
    Thanks

    double d = Double.parseDouble(new String(byteDouble)); Java doesn't seem to accept to convert byteDouble to a String...
    Exception in thread "main" java.lang.NumberFormatException: For input string: "[B@1d9fd51"
      at java.lang.NumberFormatException.forInputString (NumberFormatException.java:48)
      at java.lang.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:1213)

  • Conversion of String to byte[ ]

    Hi everybody
    I have a Byte[] value in one of our client database it seems like this -- 00033DB7FB87EC4EB371BCC9D3BF13EC
    when they import into CSV it became String
    I need to Dump into my database what ever you see in that Byte[].the value is already a conversion only so i need to dump as it is.
    now the real problem is how to convert the same String as Bytes
    if i use String.getBytes() it exceeding the Field Length
    my filed length in the database is Binary (16)
    Plz do the needful
    Thanks for ur Help in advance

    So System.out.println(theString) results in "00033DB7FB87EC4EB371BCC9D3BF13EC"?
    Then .getBytes() is not what you need. It will get the bytes representing this unicode string in a specific encoding (such as ISO-8859-1, UTF-8 or the like).
    You need to parse to digits each as hexadecimal numbers (using Integer.parseInt() for example, don't forget to specify the radix 16) and convert that to a byte[] array (the length of the byte array should be half the size of the String).
    Warning: because Java knows only signed ints, you'll have to jump through some hoops to get the correct value. Assuming String a contains 2 hexadecimal digits, you get the byte value like this:
    byte b = (byte) (Integer.parseInt(a,16) & 0xFF);

  • String to Byte convertion related question. SMS related

    Hi all
    I need to ask more indepth question regarding string to bytes convertion. I need to have a constructed message format with a length of 161 bytes. Here's are the details:-
    String message - 160 bytes allocation.
    Message length - 1 byte allocation.
    For converting the message string into byte I can use
    byte b1[] = message.getBytes();
    And i know to get the length of the message I can just use
    message.length();
    So my questions are :-
    1) I need some help on how i'm supposed to convert the length message values and assign it into the message length variables which have 1 byte allocation.
    2) Besides text, the message string can also be a hex value data. Hence it it possible that I can convert the hex data into byte and still maintain within the 160 bytes allocation ? Coz most of the times the hex data length will be > 160 but < 255 characters length. example :-
    06050415810000024a3a7d35bd35bdb995e535bd41c9bd89b194040082986417614819817624e3105d85206605e09390391394417817817819817824e40e44e5104a04a04a05205105d85206605d8938c417614819817824e40e44e5105e05e05e06605e093903913944128128128148146800
    Anyone can help ?
    Thank You in Advanced

    First of all. One character in a string can occupie
    more than one byte in the destination array, so
    String.length can be != bytes.length.
    A byte in java is always signed, so the value will be
    in the range -128 to +127.
    KajHi Kaj,
    Since you put it in that way, is there any tips u can give me on how I'm supposed to calculate the length of the string and set the value in byte ?
    Or do I need to convert the string into bytes array first and then get the length ?
    Thanks

  • String to byte[] help...please?

    this might be a very easy task for you guys..but not for me....
    please tell me how to convert a string to byte[] ????
    i need to retrieve a string from a db. the data i need to retrieve is encode (base 64). that is why i need to use Base64() of rg.apache.commons.codec.binary..
    please help me...any ideas will be very much appreciated....

    A cursory search of "Free Java Base64 Decoder" got exactly what you are looking for on the first hit.
    http://ostermiller.org/utils/Base64.html
    Please use Google first.
    - Saish

  • A regular expression to detect a blank string...

    Anyone know how to write a regular expression that will detect a blank string?
    I.e., in a webservice xsd I'm adding a restriction to stop the user specifying a blank string for an element in the webservice operation call.
    But I can't figure out a regular expression that will detect an entirely blank string but that will on the other hand allow the string to contain blank spaces in the text.
    So the restriction should not allow "" or " " to be specified but will allow "Joe Bloggs" to be specified.
    I tried [^ ]* but this wont allow "Joe Bloggs" to pass.
    Any ideas?
    Thanks,
    Ruairi.

    Hi ruairiw,
    there is a shortcut for the set of whitespace chars in Java. It is the Expression *\s* which is equal to *[ \t\n\f\r\u000b]*.
    With this expression you can test whether a String consists only of whitespace chars.
    Expamle:
    String regex = "\\s*"; // the slash needs to be escaped
    // same as String regex = "[ \t\n\f\r\u000b]";
    System.out.println("".matches(regex)); // true
    System.out.println("   ".matches(regex)); // true
    System.out.println("  \r\n\t ".matches(regex)); // true
    System.out.println("\n\nTom".matches(regex)); // false
    System.out.println("   Tom Smith".matches(regex)); // falseBesh Wishes
    esprimo

  • Converting String to byte array

    Hi,
    There is a code for converting String to byte array, as follows:
         public byte[] toByteArray(String s)
              char[] c = s.toCharArray();
              int len = c.length;
              byte[] b = new byte[len * 2];
    for ( int i = 0 ; i < len ; i++ )
         b[i * 2] = (byte)(c);
         b[(i * 2) + 1] = (byte)(c[i] >> 8);
    return b;
    But this isn't doing the conversion properly. For example, for the � (euro) symbol, it converts to some other unreadable symbol. Also, same is the case for square brackets. Any idea why this' so? What's wrong with the above code?
    The encoding format is UTF-8.
    Thanks.

    > In fact, I tried with String.getBytes() too, but leads to the same problem, with those specific symbols.
    Did you try the String.getBytes(String charsetName) method?
    Both methods have been around since Java 1.1.
    It's an extremely important skill to learn to read the API and become familiar with the tools you will use to program Java. Java has an extensive set of online documentation that you can even download for your convenience. These "javadocs" are indexed and categorized so you can quickly look up any class or method. Take the time to consult this resource whenever you have a question - you'll find they typically contain very detailed descriptions and possibly some code examples.
    Java� API Specifications
    Java� 1.5 JDK Javadocs
    Best of luck!
    ~

  • How to get the string's byte length?

    I have some string,I want to get the string's byte length,how
    can do it?
    for example:
    <cfoutput>#len('hihi,这是测试')#</cfoutput>
    output is 9
    I want to get the byte length is 14, how can i get it?
    Thanks.

    >> Fair cop. I didn't realise that asc() returned the
    codepoint rather than the
    > actual character code.
    >
    > and what would be the difference?
    Oh, sorry, whatever the term is (I'm crap with jargon). The
    value returned
    by asc() for those chars was only two bytes (ie: four hex
    digits). I
    didn't realise there was more to it than that, and that
    2-byte value maps
    to some other THREE byte value. I need to do some reading...
    > that's what both cf & java counted as the length.
    CHARACTER length, sure. No-one's disputing that. On the other
    hand,
    no-one's asking about it, either.
    > by adding a BOM you've already effected the encoding,
    which may or may not
    > match the original. so you still don't know how many
    bytes were in the original
    > string.
    [groan]
    Yes, that's a reasonable strawman there. I was only putting
    it in a file
    so I could save it and check the number of bytes occupied by
    the data.
    Clearly... CLEARLY... the OP is not asking for a character
    length of that
    string. They've said as much.
    I copy and pasted the string from their post, and used it as
    a
    demonstration of how "nine" is not the right answer for the
    BYTE LENGTH of
    that string. Whether or not the original string was UTF-8,
    UTF-16 or
    special-marmoset-encoding, it almost certainly was NOT in a
    fictitious kind
    encoding in which each of those particular characters only
    occupied one
    byte each, which would mean that "nine" is the correct answer
    to the
    question.
    When I copied those characters from either the web browser
    for from my
    text-based news agent, notepad identified them (and rendered
    them
    correctly) as UTF-8, so I'm fairly confident they ARE UTF-8.
    Of course
    this could be down to some intermediary encoding (pasting
    them in to the
    original posting, for example, via some encoding-transforming
    mechanism),
    but Occam's Razor suggests the original question was from a
    UTF-8 POV.
    But maybe we should quit speculating and ask the OP. Unless
    they've
    buggered off in despair of how drawn out all this is getting.
    For which I
    would not blame them.
    Adam

  • Conversion from hex string to bytes withh out ascii

    how to convert hex string to byte numbers without ascii codes,then all the converted bytes should come into a packets

    rajkumar5 wrote:
    how to convert hex string to byte numbers without ascii codes,then all the converted bytes should come into a packets
    What people consider ASCII and Hex with strings varies so much, you pretty much need to supply an example.  The best way is to create a VI with default data in the string control and indicator (to show what you want out).

  • Reading 21576 bytes of data at offset 3 in a buffer of total size 114

    Logs claim it's a 'buffer overflow' - [2015-Jan-05 22:32:41] RDP (0): Exception caught: BufferOverflowException in file '../../gryps/misc/containers/flexbuffer.h' at line 421
    Specifics: 
    attempting to connect to virtual box running on localhost:55985
    OSX: 10.9.5
    RDP: 8.0.12
    VirtualBox: 4.3.20
    [2015-Jan-05 22:32:41] RDP (0): --- BEGIN INTERFACE LIST ---
    [2015-Jan-05 22:32:41] RDP (0): lo0 af=18 addr= netmask=
    [2015-Jan-05 22:32:41] RDP (0): lo0 af=30 (AF_INET6) addr=::1 netmask=ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff
    [2015-Jan-05 22:32:41] RDP (0): lo0 af=2 (AF_INET) addr=127.0.0.1 netmask=255.0.0.0
    [2015-Jan-05 22:32:41] RDP (0): lo0 af=30 (AF_INET6) addr=fe80::1%lo0 netmask=ffff:ffff:ffff:ffff::
    [2015-Jan-05 22:32:41] RDP (0): gif0 af=18 addr= netmask=
    [2015-Jan-05 22:32:41] RDP (0): stf0 af=18 addr= netmask=
    [2015-Jan-05 22:32:41] RDP (0): en0 af=18 addr= netmask=
    [2015-Jan-05 22:32:41] RDP (0): en0 af=30 (AF_INET6) addr=fe80::2acf:e9ff:fe1a:cc0d%en0 netmask=ffff:ffff:ffff:ffff::
    [2015-Jan-05 22:32:41] RDP (0): en0 af=2 (AF_INET) addr=192.168.10.108 netmask=255.255.255.0
    [2015-Jan-05 22:32:41] RDP (0): en4 af=18 addr= netmask=
    [2015-Jan-05 22:32:41] RDP (0): en5 af=18 addr= netmask=
    [2015-Jan-05 22:32:41] RDP (0): bridge0 af=18 addr= netmask=
    [2015-Jan-05 22:32:41] RDP (0): p2p0 af=18 addr= netmask=
    [2015-Jan-05 22:32:41] RDP (0): vboxnet0 af=18 addr= netmask=
    [2015-Jan-05 22:32:41] RDP (0): vboxnet1 af=18 addr= netmask=
    [2015-Jan-05 22:32:41] RDP (0): vboxnet2 af=18 addr= netmask=
    [2015-Jan-05 22:32:41] RDP (0): vboxnet3 af=18 addr= netmask=
    [2015-Jan-05 22:32:41] RDP (0): vboxnet4 af=18 addr= netmask=
    [2015-Jan-05 22:32:41] RDP (0): --- END INTERFACE LIST ---
    [2015-Jan-05 22:32:41] RDP (0): correlation id: 10b4ea14-964f-83df-bf55-4ff43fb10000
    [2015-Jan-05 22:32:41] RDP (0): Resolved 'localhost' to '127.0.0.1' using NameResolveMethod_DNS(1)
    [2015-Jan-05 22:32:41] RDP (0): Resolved 'localhost' to '::1' using NameResolveMethod_DNS(1)
    [2015-Jan-05 22:32:41] RDP (0): Resolved 'localhost' to 'fe80:1::1' using NameResolveMethod_DNS(1)
    [2015-Jan-05 22:32:41] RDP (0): Exception caught: BufferOverflowException in file '../../gryps/misc/containers/flexbuffer.h' at line 421
    User Message : Reading 12112 bytes of data at offset 3 in a buffer of total size 82
    [2015-Jan-05 22:32:41] RDP (0): correlation id: 10b4ea14-964f-83df-bf55-4ff43fb10000
    [2015-Jan-05 22:32:41] RDP (0): Resolved 'localhost' to '127.0.0.1' using NameResolveMethod_DNS(1)
    [2015-Jan-05 22:32:41] RDP (0): Resolved 'localhost' to '::1' using NameResolveMethod_DNS(1)
    [2015-Jan-05 22:32:41] RDP (0): Resolved 'localhost' to 'fe80:1::1' using NameResolveMethod_DNS(1)
    [2015-Jan-05 22:32:41] RDP (0): Exception caught: BufferOverflowException in file '../../gryps/misc/containers/flexbuffer.h' at line 421
    User Message : Reading 21576 bytes of data at offset 3 in a buffer of total size 114
    [2015-Jan-05 22:32:41] RDP (0): Protocol state changed to: ProtocolConnectingNetwork(1)
    [2015-Jan-05 22:32:41] RDP (0): Protocol state changed to: ProtocolNegotiatingCredentials(2)
    [2015-Jan-05 22:32:41] RDP (0): Protocol state changed to: ProtocolConnectingNetwork(1)
    [2015-Jan-05 22:32:41] RDP (0): Protocol state changed to: ProtocolNegotiatingCredentials(2)
    [2015-Jan-05 22:32:41] RDP (0): Protocol state changed to: ProtocolDisconnecting(7)
    [2015-Jan-05 22:32:41] RDP (0): Protocol state changed to: ProtocolDisconnected(8)
    [2015-Jan-05 22:32:41] RDP (0): ------ END ACTIVE CONNECTION ------
    ps: the editor for posting on this forum is absolutely the most terrible I had ever seen.

    Hi,
    Please let us know which OS you are trying to connect. Because if you are running Windows 8 and not Windows 8 Pro then you won't be able to connect to your PC from any device. Windows 8 can't host an RDP session.  
    Remote Desktop Client on Mac: FAQ
    http://technet.microsoft.com/en-in/library/dn473006.aspx
    Hope it helps!
    Thanks.
    Dharmesh Solanki
    TechNet Community Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Support, contact [email protected]

  • From MD5-string to byte array

    Hi fellows, I'm writing a simple cracker for MD5. The hash value has to be passed at command line as argument.
    e.g.
    java Cracker 0cc175b9c0f1b6a831c399e269772661In order to decode the hash value I'm using a brute force approach: therefore I compare a series of strings with the hash value by using the method of the class MessageDigest isEqual(byte[] a, byte[] b). So I encode each string and compare the byte array I get with the byte array of the hash value.
    Here it comes the trouble I'm in:
    when I try to get a bytes array of the MD5 hash value passed as argument of the program , I do get something, but it's not something that the isEqual method of MessageDigest can use to compare. As a result any attempt during the execution of brute force fails, even though the key is one of the string being checked.
    Perhaps am I facing a format problem? Any idea?
    Sorry for my english, it's not my first language
    Thanks to whoever will help

    Almost all questions in these forums about brute force attack on MD5 (or SHA1 or SHA256 etc etc etc) are school, college or university projects and of no practical use. This is almost certainly such a project.
    Unless things have changed in the last year, there is no practical brute force attack on MD5 whereby an input can be generated from an arbitrary output even though two inputs with the same output can be fabricated. A dictionary attack is feasible if no salt is used or a known salt is used since one only has to build the dictionary for one salt value. If a different salt is used for each entry being attacked then a dictionary will be need for each salt being used. Of course if one takes the simple precaution of not using anything that is likely to be in a dictionary then the dictionary attack will likely fail.

  • How to get the size of a string in bytes

    Morning,
    I’m trying to get the length in bytes of a string, the characters below are 3 byte UTF-8, but when I display
    The length of either int, looks like is double I got 120 and I think it should be 60. Any idea
    String requiredMsg = "όόόόόόόόόόόόόόόόόόόό";
    int byteCountUTF8 = requiredMsg.getBytes("UTF-8").length;
    int byteCountUTF8 = requiredMsg.getBytes().length;
    thanks

    OK, it is not 'o with acute', but rather 'Greek small omicron with tonos'.
    This page may help you sort it out:http://www.fileformat.info/info/unicode/char/3cc/index.htm.
    According to the page and to my tests, this Unicode 03CC has a 2 bytes (not 3) UTF-8 representation.
    String requiredMsg = "\u03CC";
    System.out.println(requiredMsg.getBytes("UTF-16").length);
    System.out.println(requiredMsg.getBytes("UTF-8").length);
    System.out.println(requiredMsg.getBytes().length); // In WindowsResult on my machine:
    4
    2
    1

  • Detect substring in string

    Hi all,
    I am new to ABAP and hoping you guys can let me know if there is a better way to check for a substring in a string.
    I need to detect a substring (or should call it a word) 'CNF' in a string, and it need to be a word itself and not part of another word (example, PCNF). This substring can appear in the beginning of the string or the end of the string. To explain this clearly let me show you a list of string that should return me true or false:
    Return true:
    MCNF CNF REL
    CNF MCNF REL
    CNF REL
    REL CNF
    MCNF REL CNF
    Return false:
    MCNF PCNF REL
    REL MCNF PCNF
    One way i think of doing it is to split it using space into a itab, loop thru and check. Is there a better way to do this?

    Hello,
    Please look at the example below:
    Example
    DATA F(50).
    MOVE 'Alaska Texas California' TO F.
    SEARCH F FOR 'Clfrn' ABBREVIATED.
    Here, SY-SUBRC is set to 0, since not only does the string 'Clfrn' occur (separated by other characters) in 'California', but 'Clfrn' and 'California' begin with the same letter.
    Addition 2
    ... STARTING AT n1
    Effect
    Searches the field f starting from the position n1. Here, n1 can also be a field containing the corresponding value. The first character in the field f is in position 1.
    When you use the addition STARTING AT, the position specified for the found pattern in SY-FDPOS does not refer to the start of the field, but to the position n1.
    Addition 3
    ... ENDING AT n2
    Effect
    Searches the field f up to the position n2.
    Addition 4
    ... AND MARK
    Effect
    If the search string g is found, all the characters of the search string and all the characters occurring in between (in the case of SEARCH ABBREVIATED) are converted to upper case in the field f.
    Example
    DATA F(20) VALUE 'Peter Paul Mary'.
    SEARCH F FOR '*UL' AND MARK.
    SY-SUBRC is now set to 0, since the search string was found in 'Paul'. SY-FDPOS has the value 6, since the character string found starts at the offset 6. Also, the search string is marked, so that the new contents of f are as follows:
    'Peter PAUL Mary'
    Hope this helps...
    P.S. Please award points for useful answers.

  • Float to byte - String to byte

    Hi All,
    I am writing a Binary file writer.
    the convertion is made from several java type (int, float, double, String, ...) to bytes equivalent.
    I have a reader that reads the files that I am generating through my prog.
    In some fields, i put 0.0f value once It is read it return some weird values like 9.66338e-13
    how can solve this problem ?
    thanks in advance

    If you take time to read it would ne better...and you can help efficiently...
    the thing i don't want to talk in depth details...
    There is a telecom system which read a binary file. with a specific format...in that format, there is some fields with float type.
    And there is whole bunch of checkin to validate the type and the format and the size of each field...
    I am writing an app that generate those files...in fact, they are generated
    and also read by the T-system...but in the float fields, the data which is supposed to be 0.0f is something else.
    So the question, should i fix something with float type to get the expected result...like precision for exampl..or i do not know...
    And none have said it's a java problem...
    it's just the matter i have missed something...
    Hope you got it...
    thanks for help...and not blabla

Maybe you are looking for