Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9136507
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:57:42+00:00 2026-06-17T08:57:42+00:00

I’m working on a basic file carver and I’m currently stuck on calculate the

  • 0

I’m working on a basic file carver and I’m currently stuck on calculate the byte position of the file.

I’ve worked out that I need a piece of code to perform the following steps;

  1. Locate the $searchQuery in the variable
  2. Remove the rest of the string after the $searchQuery is found
  3. Count the number of fields that now exist within the variable
  4. Minus 2 from this variable to take into account the Hex Offset and the $searchQuery itself
  5. Then multiply the answer by two to get the correct byte count

An example of this would be;

  1. Locate “ffd8” within “00052a0: b4f1 559c ffd8 ffe0 0010 4a46 4946 0001”
  2. Variable is updated to “00052a0: b4f1 559c ffd8”
  3. $fieldCount is assigned the value of “4”
  4. $fieldCount=((fieldCount-2))
  5. $byteCount=((fieldCount*2))

I have a basic idea of how to do everything but count the number of fields in the variable. For example, how would I count how many fields there are in the variable until the $searchQuery is found? And similarly, how do I count the number of fields once I’ve removed the unnecessary part of the string?

After locating the $searchString with grep I have no idea how to proceed. My current code looks like this;

#!/bin/bash
#***************************************************************
#Name:          fileCarver.sh
#Purpose:       Extracts files hidden within other files
#Author:        
#Date Written:      12/01/2013
#Last Updated:      12/01/2013
#***************************************************************

clear

#Request user input
printf "Please enter the input file name: "
read inputFile
printf "Please enter the search string: "
read searchString

#Search for the required string
searchFunction()
{
    #Search for required string and remove unnecessary characters
    startHexOffset=`xxd $1 | grep $2 | cut -d":" -f 1`
    #Convert the Hex Offset to Decimal
    startDecOffset=$(echo "ibase=16;${startHexOffset^^}" | bc)
}

searchFunction $inputFile $searchString


exit 0

Thanks for the help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T08:57:43+00:00Added an answer on June 17, 2026 at 8:57 am

    You might find this easier if you convert the file to hex in a simpler format. For example, you can use the command

    hexdump -v -e '/1 "%02x "' $FILE
    

    to print the file with every byte converted to exactly three characters: two hex digits and a space.

    You could find all instances of ffd8 prefixed with their byte offset:

    hexdump -v -e '/1 "%02x "' $FILE | grep -Fbo 'ff d8 '
    

    (The byte offsets need to be divided by 3.)

    So you could stream the entire file from the first instance of ffd8 using:

    tail -c+$((
      $(hexdump -v -e '/1 "%02x "' $FILE | grep -Fbo 'ff d8 ' | head -n1 | cut -f1 -d:)
      / 3 + 1)) $FILE
    

    (That assumes that whatever you use to display the file knows enough to stop when it hits the end of the image. But you could similarly find the last end marker.)

    This depends on GNU grep; standard Posix grep lacks the -b option. However, it can be done with awk:

    tail -c+$(
        hexdump -v -e '/1 "%02x\n"' $FILE |
        awk '/d8/&&p=="ff"{print NR-1;exit}{p=$1}'
      ) $FILE
    

    Explanation of options:

    tail    -c+N    file starting at byte number N (first byte is number 1)
    
    hexdump -v      do not compress repeated lines on output
            -e 'FORMAT'  use indicated format for output:
                /1       each format consumes 1 byte
                "%02X "  output two hex digits, including leading 0, using lower case,
                         followed by a space.
    
    grep    -F      pattern is just plain characters, not a regular expression
            -b      print the (0-based) byte offset of the... 
            -o      ... match instead of the line containing the match
    
    cut     -f1     output the first field of each line
            -d:     fields are separated by :
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want use html5's new tag to play a wav file (currently only supported
In my XML file chapters tag has more chapter tag.i need to display chapters
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
I need a function that will clean a strings' special characters. I do NOT
I'm parsing an XML file, the creators of it stuck in a bunch social
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.