"; */ ?>


04
Apr 07

SED to parse and modify XML element nodes

In one of my previous articles I showed how AWK can be used to get a very useful statistic from server log. Today I want to introduce my other friend – SED, which will help us to modify values of element nodes within an XML file.

Here is a little info on SED from wikipedia:

sed (which stands for Stream EDitor) is a simple and powerful computer program used to apply various textual transformations to a sequential stream of text data. It reads input files line by line, applying the operation which has been specified via the command line (or the sed script), and then finally outputs the line. It was originally developed from 1973 to 1974 as a Unix utility by Lee E. McMahon of Bell Labs, but today sed is now available for Unix (BSD, Mac OS X), Linux, and Win32, as well as many other platforms.

Ok, let’s see what is given. By complete accident we have an access to an XML request (file) from Yanik’s bank (ING), that performs a transfer of $1,000,000.00 dollars to his account today in exactly one hour. Here is what the request looks like (goodnews.xml):

<?xml version="1.0" encoding="ISO-8859-1"?>
<goodnews>
 
      <to>Yanik</to>
      <from>ING Bank</from>
      <date>04/01/2007</date>
      <amount>$1,000,000.00</amount>
      <account>0024549Y48K3-843</account>
      <message>We are pleased to inform you that the above amount was transferred to your bank account</message>
 
</goodnews>

Now, what if we could just made a slight change to this request, and become a receiver of that million dollars – would not that be cool!? Well, I am not asking Yanik here, for an obvious reason… The answer is – yes, it’d be cool and SED can help us archive our goal. Here is how.

Below, I wrote a small shell script that will be using SED. The script will take three parameters from a command line:

    “xml filename”, “element name” and “new value”

Then it will extract the value from the “element name”, and substitute it with a “new value” – that’s it – that is how simple it is. Does it smell like a million dollars already? :)

Here is the code (relement.sh):

# Check that exactly 3 values were passed in
if [ $# -ne 3 ]; then
echo 1>&2 “This script replaces xml element’s value with the one provided as a command parameter \n\n\tUsage: $0 <xml filename> <element name> <new value>exit 127
fi
 
echo "DEBUG: Starting... [Ok]\n"
echo "DEBUG: searching $1 for tagname <$2> and replacing its value with '$3'"
 
# Creating a temporary file for sed to write the changes to
temp_file="repl.temp"
 
# Elegance is the key -> adding an empty last line for Mr. “sed” to pick up
echo ” ” >> $1
 
# Extracting the value from the <$2> element
el_value=`grep<$2>.*<.$2>$1 | sed -e “s/^.*<$2/<$2/| cut -f2 -d”>| cut -f1 -d”<`
 
echo "DEBUG: Found the current value for the element <$2> - '$el_value'"
 
# Replacing elemen’s value with $3
sed -e “s/<$2>$el_value<\/$2>/<$2>$3<\/$2>/g” $1 > $temp_file
 
# Writing our changes back to the original file ($1)
chmod 666 $1
mv $temp_file $1

Let’s run it now and get that million dollars, that we are after:

[me at server]~: ./relement.sh goodnews.xml account my-secure-account
DEBUG: Starting... [Ok]
 
DEBUG: searching goodnews.xml for tagname <account> and replacing its value with 'my-secure-account'
DEBUG: Found the current value for the element <account> - '0024549Y48K3-843'
DEBUG: <account>0024549Y48K3-843</account> was successfully changed to <account>my-secure-account</account>
 
DEBUG: Exiting... [Ok]
 
[me at server]~: cat goodnews.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<goodnews>
 
      <to>Yanik</to>
      <from>ING Bank</from>
      <date>04/01/2007</date>
      <amount>$1,000,000.00</amount>
      <account>my-secure-account</account>
      <message>We are pleased to inform you that the above amount was transferred to your bank account</message>
 
</goodnews>

Now we are getting all the money and not Yanik (well it is MY-secure-account, so technically I get it :) ).

Here is the nitty-gritty details of how that financial operation was possible…

Of course, the heart of this script is this line:

el_value=`grep "<$2>.*<.$2>" $1 | sed -e "s/^.*<$2/<$2/" | cut -f2 -d">"| cut -f1 -d"<"`

And here is what happens here:

    1. We grep “<element>whatever</element>” from the file ($1)

    2. Then we apply sed to search to ignore everything from the beginning of the line to the “<element”

    3. And finally we cut the value of this element which is located in between greater and less signs “>value<“

Easy, right?

Now let us look at this line:

sed -e "s/<$2>$el_value<\/$2>/<$2>$3<\/$2>/g" $1 > $temp_file

which uses sed’ (or vi’s) ‘s/search/replace/g” pattern to do the job – to replace all the “<element>oldvalue</element>” to “<element>newvalue</element>”. After that it saves it in a temp file, before replacing the original file.

The line

echo " " >> $1

makes sure that the source file has an empty last line, so sed can identify the “end of file” correctly

There is also one thing to mention – if you export Microsoft (e.g. M$ Word) document to XML, in order to change anything (properties) there, add these lines:

sed -e "s/<w:t>$el_value</<w:t>$3</g" $1 > $temp_file
chmod 666 $1
mv $temp_file $1

it will change all the corresponding elements to the property you need to change.

Now we are completely empowered! Quit your job – learn SED, and earn millions! No.. rather – billions!

Feel free to ask questions or leave comments.


04
Apr 07

Music Video Clip of the day: Guns N’Roses “Don’t Cry”

Don’t Cry” is a song by Guns N’ Roses, two versions of which were released simultaneously on different albums. The version with the original lyrics is the fourth track on Use Your Illusion I; the version with the alternate lyrics is the thirteenth track on Use Your Illusion II. Only the vocal tracks differ, and even then only in the verses; however, in those verses, not only are the words entirely different, but the meter and melody are also slightly different.


02
Apr 07

The big heart of the “Reign over me”

  Movies that were coming from the other side of the planet (US) in late 80s beginning of 90s were not kind of movies that would flow together with your feelings, or open up your mind widely, they were rather: “Cobra”, “Comando”, “Bloodsport” etc.. – not that many Hollywood movies were translated to Russian and available for the general audience (USSR) to watch. So we were not too spoiled with Hollywood classics, so to speak..

  Later on, in mid 90s, when I first saw “Billy Madison”, “Happy Gilmore” and, then later on, “The Waterboy”, they were translated so poorly, that seemed extremely dull and stupid – and that was my take on Adam Sandler, and that what I took with me to the 21st century…

  Things have changed a lot when “Hollywood doors” opened up to a boundless flow of thousands of new and old movies from US to the former USSR, and, of course, when I got to know English a little better.
  I watched movie after movie, and little by little everything started to make sense – I learned to see and appreciate the beauty that was always there, that before I’ve never got a chance to see, or the language to understand. That was phenomenal! (well, for me it was).

  And I did re-discovered Adam Sandler and his work, it finally got to me after a decade. “The Wedding Singer”, “Big Daddy”, “Mr. Deeds”, “Spanglish” – they all “appeared naked” in front of me, and I could feel their kindness, sincerity, and a big and honest heart!

    picture is taken from rottentomatoes
Reign Over Me '2007

  “Reign over me” shows Adam in slightly different angle. While his character (Charlie Fineman) is sort of a combination of “Punch-Drunk Love”, “Big Daddy” and “Mr.Deeds”, it reveals a new inner perception of the world around him. In the movie Charlie “pairs up” with a successful dentist, his former college roommate, Alan Johnson (Don Cheadle), which creates a bridge between Charlie’s insularity and Alan’s overall life unhappiness. During the movie Alan is trying to help Charlie get through an awful tragedy that lives inside Charlie’s mind and soaked with his whole essence. By helping him, Alan comes to realize that Charlie, in spite of his problems has something that such successful dentist as himself does not have – Charlie is free!

  Movie is witty, funny and very sad at the same time. It has this unbelievable power, when you’re watching it, you know it is long, but every 5 minutes, closer to the end, you are alert and constantly worried that it is going to end, when you really want it to be “just a little longer”.

  As most of the previous work of Adam Sandler “Reign over me” has a big, kind and honest heart! There are certain people in our world who have this unique talent, and are able to see and feel “This Heart” – others just go to see comedy or call themselves “critics”.


01
Apr 07

Unlock Motorola V3 RAZR and go to the Moon!

Disclaimer October the 8th of 2010: I have closed the comments for this post, since people are posting a lot of advertisement + some people claim that “scotty2_8.26_downgrader_v2” has a virus. I have not written the downgrader, and it worked for me and many other people without any problems, but if you are afraid there is a virus, don’t use it: it is as simple as that.

Unlock Motorola V3 Lot’s of forum talks, lot’s of articles on Motorola internals, but none seemed to work 100%, and rather worked 97%. There was still this 3% that kept Motorola V3 RAZR owners from unlocking the phone… Here are tested, and proved to complete all 100%, steps that will let you unlock your Moty.

First, let’s get ready. All the tools that you can download below are MS Windows based (if you are using different OS, like Mac or, like me – Ubuntu, you can install MS Windows in a virtual box).

Ok, so assuming you are using MS Windows, these are the tools you will need to use:

  • MiniUSB to USB cable miniusb to usb cable in order to connect your RAZR V3 to PC/Laptop.

  • p2k drivers 2.9” – This is a set of drivers that will enable your PC/Laptop and RAZR V3 to communicate.

  • scotty2_8.26_downgrader_v2” – this is the tool written by scotty2 which downgrades your phone’s bootloader from (8.26, 8.23, 7.E0) to 7.D0, which is needed for the next tool to unlock it.

  • “P2K_Easy_Tool_v37” – this is an actual “unlocker” tool.

    (Google asked to remove the link for “P2K_Easy_Tool_v37”. you can find it using any search engine)


Let’s do it

First thing first…

Step 1. Download the tools above, unpack them (unrar, unzip – here is a good tool for that tugzip)

Step 2. Plug in your phone to the computer using (#4) miniUSB to USB cable and install the drivers. Windows will ask you to install the drivers once the phone is plugged in, so just point it to the right directory where you unpacked them

Step 3. Turn off your phone

Step 4. Press and hold two buttons the star (*) and the pound (#) and while holding press the power button – this will bring you to something that Motorola people call “the flash screen”. On the top of the screen you will see something like this:

Boot Loader
      08.26
      SW Version:
      R374_G_0E.41.C
      3R_0
      Ok to Program
      USB
      Transfer Mode

Step 5. Now you will need to run a scotty2’s tool to downgrade the Boot Loader (in this case) from 08.26 to 07.D0. For this (unpack the scotty’s zip and) run “downgrader.exe”. Follow the instructions and the output of the program should look similar to:

Waiting for phone... Found!
Getting phone interface information...
Registry Interface #: 3
Interface Description: Motorola Flash Interface
Interface LocInfo: S Flash Neptune LTE
Opening phone for communication... Success!
Getting software version… R374_G_0E.41.C3R_B,
Flex: GSMV3VCRGR01NA120
Getting bootloader version… 08.26
Getting flash mode… SFLASH (Normal)
Sending ramldr… Success.
Jumping… ACK JUMP,03FD0010
Saving CG1 backup… Success.
Sending Restart Command…
 
Waiting for driver to disconnect... Done!
Waiting for phone… Found!
Opening phone for communication... Success!
Sending ramldr… Success.
Jumping… ACK JUMP,03FD0010
Erasing… ACK ERASE,C
Flashing Exploit CG1… Success.
Sending Restart Command…
Waiting for driver to disconnect... Done!
Waiting for phone… Found!
Opening phone for communication... Success!
Sending ramldr… Success.
Jumping…
Erasing… ACK ERASE,C
Downgrading bootloader… Success.
Sending restart command…
Waiting for driver to disconnect... Done!
Waiting for phone… Found!
Opening phone for communication... Success!
Getting bootloader version… 08.23
Getting flash mode… SFLASH (Normal)
Sending ramlrd… Success.
Jumping… ACK JUMP,03FD0010
Erasing… ACK ERASE,C
Sending Restart Command…
Waiting for driver to disconnect... Done!
Waiting for phone… Found!
Opening phone for communication... Success!
Sending ramldr… Success.
Jumping… ACK JUMP,03FD0010
Erasing… ACK ERASE,C
Downgrading bootloader… Success.
Sending Restart Command…
Waiting for driver to disconnect... Done!
Waiting for phone… Found!
Opening phone for communication... Success!
Getting bootloader version… 07.D0
Getting flash mode… SFLASH (Normal)
Sending ramldr… Success.
Jumping… ACK JUMP,03FD0010
Erasing… ACK ERASE,C
Flashing Backup CG1… Success.
Sending Restart Command…
Bootloader is now 7.D0, have fun modding!

If you have problems on the step “Waiting for driver to disconnect” (it supposed to auto restart after this step), after the phone turned itself off, just turn it on again as it described in step 3 (Press and hold * and #, then while holding press the power button) At this point you should see that your Boot Loader has changed:

Boot Loader
07.DO
SW Version:
…

Step 6. Now it is time to run the “p2k_easy_tool_v37” unlocking tool. Run “P2K_Easy_Tool_v37.exe”,

6.1 Go to “Locks” tab

6.2 Choose your phone model (V3 RAZR) from the “Phone Model” drop down

6.3 Check “Unlock SP”

6.4 Click on “Do Selected Jobs” button

And follow the instructions. Here is the snapshot of successful result: p2k easy tool - successful result

Step 7. That should complete your journey, and Moty V3 RAZR should be good to go! Now you can take it to the Moon – it’ll work just fine!

Note the last fact is not tested due to the limited knowledge about Moon’s Global System for Mobile communication


01
Apr 07

Music Video Clip of the day: DDT Belaya Reka

DDT (or ДДТ in Cyrillic) is a popular Russian rock band founded by its permanent lead singer, Yuri Shevchuk (Юрий Шевчук), in Ufa in 1981.

The original band comprises:

  • Yuri Shevchuk – vocals, guitar
  • Vladimir Sigachev – keyboard
  • Rustem Asanbayev – guitar
  • Gennadi Rodin – bass
  • Rustam Karimov – percussion