grep util ? on binary files

grep util ? on binary files

am 24.10.2007 06:09:30 von harryooopotter

I am trying to locate a hard-coded path in a Java application
with tens of thousands of files on a Linux box. Apparently a
developer had hard-coded 'c:\somefolder' in one or more Java class
files. So, find . -type f -exec grep -il 'c:\\somefolder' {} \;
has returned nothing. But some log files indicated that the Java
app could not be initiated due to not able to find
'c:\somefolder ....some.jar' on an Linux system.

How can I locate such class file(s) with a pattern 'c:\somefolder'
embedded? Is there such a beast as "binary grep" which can grep some
patterns on binary (Java class) files?

TIA

Re: grep util ? on binary files

am 24.10.2007 06:22:17 von Icarus Sparry

On Wed, 24 Oct 2007 04:09:30 +0000, Harry331 wrote:

> I am trying to locate a hard-coded path in a Java application with tens
> of thousands of files on a Linux box. Apparently a developer had
> hard-coded 'c:\somefolder' in one or more Java class files. So, find .
> -type f -exec grep -il 'c:\\somefolder' {} \; has returned nothing. But
> some log files indicated that the Java app could not be initiated due to
> not able to find 'c:\somefolder ....some.jar' on an Linux system.
>
> How can I locate such class file(s) with a pattern 'c:\somefolder'
> embedded? Is there such a beast as "binary grep" which can grep some
> patterns on binary (Java class) files?
>
> TIA

Most grep programs work fine on binary files.

However it may be the case that since these are java files they are
working with 16 bit characters, rather than 8 bit ones.

Try looking for c.:.\\.s.o.m.e.f.o.l.d.e.r

Another approach would be to run a suitable version of "strings" on the
file (one which knows about 16 bit character sets, such as the one in the
at&t opensource software), and then run grep on the output of that.

Re: grep util ? on binary files

am 24.10.2007 08:42:56 von ramesh.thangamani

On Oct 24, 9:22 am, Icarus Sparry wrote:
> On Wed, 24 Oct 2007 04:09:30 +0000, Harry331 wrote:
> > I am trying to locate a hard-coded path in a Java application with tens
> > of thousands of files on a Linux box. Apparently a developer had
> > hard-coded 'c:\somefolder' in one or more Java class files. So, find .
> > -type f -exec grep -il 'c:\\somefolder' {} \; has returned nothing. But
> > some log files indicated that the Java app could not be initiated due to
> > not able to find 'c:\somefolder ....some.jar' on an Linux system.
>
> > How can I locate such class file(s) with a pattern 'c:\somefolder'
> > embedded? Is there such a beast as "binary grep" which can grep some
> > patterns on binary (Java class) files?
>
> > TIA
>
> Most grep programs work fine on binary files.
>
> However it may be the case that since these are java files they are
> working with 16 bit characters, rather than 8 bit ones.
>
> Try looking for c.:.\\.s.o.m.e.f.o.l.d.e.r
>
> Another approach would be to run a suitable version of "strings" on the
> file (one which knows about 16 bit character sets, such as the one in the
> at&t opensource software), and then run grep on the output of that.

Try using strings on the file and grep it for eg:

strings java/javaDecorator/InputTest.class | grep print

Re: grep util ? on binary files

am 24.10.2007 13:07:30 von Matteo Corti

Dear Harry,

On Oct 24, 8:42 am, ramesh.thangam...@gmail.com wrote:
> On Oct 24, 9:22 am, Icarus Sparry wrote:
> > On Wed, 24 Oct 2007 04:09:30 +0000, Harry331 wrote:
> > > I am trying to locate a hard-coded path in a Java application with tens
> > > of thousands of files on a Linux box. Apparently a developer had
> > > hard-coded 'c:\somefolder' in one or more Java class files. So, find .
> > > -type f -exec grep -il 'c:\\somefolder' {} \; has returned nothing. But
> > > some log files indicated that the Java app could not be initiated due to
> > > not able to find 'c:\somefolder ....some.jar' on an Linux system.
>
> > > How can I locate such class file(s) with a pattern 'c:\somefolder'
> > > embedded? Is there such a beast as "binary grep" which can grep some
> > > patterns on binary (Java class) files?
>
> > Most grep programs work fine on binary files.
>
> > However it may be the case that since these are java files they are
> > working with 16 bit characters, rather than 8 bit ones.
>
> > Try looking for c.:.\\.s.o.m.e.f.o.l.d.e.r
>
> > Another approach would be to run a suitable version of "strings" on the
> > file (one which knows about 16 bit character sets, such as the one in the
> > at&t opensource software), and then run grep on the output of that.
>
> Try using strings on the file and grep it for eg:
>
> strings java/javaDecorator/InputTest.class | grep print

or try javap -c on the classfiles (it shows the corresponding
bytecode)

Matteo

Re: grep util ? on binary files

am 24.10.2007 13:29:47 von Maxwell Lol

harryooopotter@hotmail.co_ (Harry331) writes:

> I am trying to locate a hard-coded path in a Java application
> with tens of thousands of files on a Linux box.

You can also use a java dissassembler.....

Re: grep util ? on binary files

am 24.10.2007 15:01:06 von Lew Pitcher

On Oct 24, 12:09 am, harryooopot...@hotmail.co_ (Harry331) wrote:
> I am trying to locate a hard-coded path in a Java application
> with tens of thousands of files on a Linux box. Apparently a
> developer had hard-coded 'c:\somefolder' in one or more Java class
> files. So, find . -type f -exec grep -il 'c:\\somefolder' {} \;
> has returned nothing. But some log files indicated that the Java
> app could not be initiated due to not able to find
> 'c:\somefolder ....some.jar' on an Linux system.
>
> How can I locate such class file(s) with a pattern 'c:\somefolder'
> embedded?
[snip]

Make a symbolic link in the java programs cwd from "c:\somefolder" to
the proper directory in which the class libraries are found. I.e.

ln -s /path/to/class/directory 'c:\somefolder'

This way, your non-portable portable app will be able to open the "c:
\somefolder" directory, even though the directory name is not standard
for your Linux system

Re: grep util ? on binary files

am 24.10.2007 21:44:19 von Nikhil

Harry331 wrote:
> I am trying to locate a hard-coded path in a Java application
> with tens of thousands of files on a Linux box. Apparently a
> developer had hard-coded 'c:\somefolder' in one or more Java class
> files. So, find . -type f -exec grep -il 'c:\\somefolder' {} \;
> has returned nothing. But some log files indicated that the Java
> app could not be initiated due to not able to find
> 'c:\somefolder ....some.jar' on an Linux system.
>
> How can I locate such class file(s) with a pattern 'c:\somefolder'
> embedded? Is there such a beast as "binary grep" which can grep some
> patterns on binary (Java class) files?
>
> TIA
>
>
>
strings | grep

Thanks, Nikhil

Re: grep util ? on binary files

am 24.10.2007 22:48:25 von Stephane CHAZELAS

2007-10-24, 04:09(+00), Harry331:
> I am trying to locate a hard-coded path in a Java application
> with tens of thousands of files on a Linux box. Apparently a
> developer had hard-coded 'c:\somefolder' in one or more Java class
> files. So, find . -type f -exec grep -il 'c:\\somefolder' {} \;
> has returned nothing. But some log files indicated that the Java
> app could not be initiated due to not able to find
> 'c:\somefolder ....some.jar' on an Linux system.
>
> How can I locate such class file(s) with a pattern 'c:\somefolder'
> embedded? Is there such a beast as "binary grep" which can grep some
> patterns on binary (Java class) files?
[...]

Install GNU grep, that can cope with binary files, then run

grep -rliF 'c:\somefolder' .

Or you can use perl.

--
Stéphane

Re: grep util ? on binary files

am 26.10.2007 00:32:01 von Paul Kimoto

On 2007-10-24, Harry331 wrote:
> I am trying to locate a hard-coded path in a Java application
> with tens of thousands of files on a Linux box. Apparently a
> developer had hard-coded 'c:\somefolder' in one or more Java class
> files. So, find . -type f -exec grep -il 'c:\\somefolder' {} \;
> has returned nothing.

Perhaps your problem has something to do with backslashes. I find
that "grep 'c:\\somefolder' doesn't do what you want.

$ /bin/echo 'c:\\somefolder'
c:\\somefolder
$ /bin/echo 'c:\\somefolder' | grep 'c:\\somefolder'
$ /bin/echo 'c:\\somefolder' | grep 'c:\\\\somefolder'
c:\\somefolder
$ /bin/echo 'c:\\somefolder' | grep -F 'c:\\somefolder'
c:\\somefolder
$ grep --version
GNU grep 2.5.3

Copyright (C) 1988, 1992-2002, 2004, 2005 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

--
Paul Kimoto
This message was originally posted on Usenet in plain text. Any images,
hyperlinks, or the like shown here have been added without my consent,
and may be a violation of international copyright law.