The moose likes I/O and Streams and the fly likes Deserializing Visual Basic 6 files in Java? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of C++ Concurrency this week in the C/C++ forum
or Spring Integration in Action in the Spring forum!
JavaRanch » Java Forums » Java » I/O and Streams
Reply Bookmark "Deserializing Visual Basic 6 files in Java?" Watch "Deserializing Visual Basic 6 files in Java?" New topic
Author

Deserializing Visual Basic 6 files in Java?

Jay Orsaw
Ranch Hand

Joined: Jun 14, 2011
Posts: 54
Okay, so I have to be able to read files that have been serialized in VB. 2 things, 1 they are serialized in Binary, and I tried to look up on how to serialize/deserialize in Binary, but didn't have much help...

Also in the VB code they talk about "TYPES" which seems to be to just be a class full of stuff...

Any information would be appreciated, any questions please ask,

thanks,

~KZ.

This message was edited 1 time. Last update was at by Bear Bibeault

Jeff Verdegan
Rancher

Joined: Jan 03, 2004
Posts: 1513
Jay Orsaw wrote:they are serialized in Binary, and I tried to look up on how to serialize/deserialize in Binary, but didn't have much help...


"Binary" is not one single format. Word files, Excel files, Java's .class files, .exe files--they're all binary and they're all very different. Java's serialization mechanism is also binary, but that doesn't mean it can read any of those other formats or whatever format your VB files use.

All "binary" really means in terms of file formats is "may contain bytes that don't translate into textual characters."

You have two basic approaches:

1) Search for a third-party Java library that knows how to read that VB6 format.

2) Find the specs for that format and write your own deserialization code.
Jay Orsaw
Ranch Hand

Joined: Jun 14, 2011
Posts: 54
Ah okay, that makes sense! I cannot open the .ser files when trying to in notepad...

I have the VB6 code, so judging by that comment I can read the VB6 files then if I know the format... Thank you!

This message was edited 1 time. Last update was at by Ulf Dittmer

Jay Orsaw
Ranch Hand

Joined: Jun 14, 2011
Posts: 54


I copied everything and made my own class. The global variables aren't in order however(do they need to be?) I made a constructor with the parameters of each and then assigned the constructor parameters to the global variables IN EXACT ORDER of the VB6 serialized file.




The error appears when reading the file... hmmm...

This message was edited 1 time. Last update was at by Jay Orsaw

Jeff Verdegan
Rancher

Joined: Jan 03, 2004
Posts: 1513
Jay Orsaw wrote:
The error appears when reading the file... hmmm...


What file? Are you trying to read the VB6 file with Java's ObjectInputStream? You can't do that. That would only work if Java's serialization format was the same as that VB6 format, which is phenomenally unlikely. Just writing a Java class that's the structural equivalent of the VB6 class doesn't magically make Java able to understand the VB6 format.

This message was edited 2 times. Last update was at by Jeff Verdegan

toddy shed
Greenhorn

Joined: Jan 28, 2012
Posts: 1
Jeff Verdegan wrote:
Jay Orsaw wrote:they are serialized in Binary, and I tried to look up on how to serialize/deserialize in Binary, but didn't have much help...


"Binary" is not one single format. Word files, Excel files, Java's .class files, .exe files--they're all binary and they're all very different. Java's serialization mechanism is also binary, but that doesn't mean it can read any of those other formats or whatever format your VB files use.

All "binary" really means in terms of file formats is "may contain bytes that don't translate into textual characters."

You have two basic approaches:

1) Search for a third-party Java library that knows how to read that VB6 format.

2) Find the specs for that format and write your own deserialization code.




thanks for the above knowledge of java,its really very nice to give information of java mixed with visual basic .I want to ask a question that is it possible to have java function enabled in visual basic



_____________
Speaking English Uk
Jay Orsaw
Ranch Hand

Joined: Jun 14, 2011
Posts: 54
Jeff Verdegan wrote:
Jay Orsaw wrote:
The error appears when reading the file... hmmm...


What file? Are you trying to read the VB6 file with Java's ObjectInputStream? You can't do that. That would only work if Java's serialization format was the same as that VB6 format, which is phenomenally unlikely. Just writing a Java class that's the structural equivalent of the VB6 class doesn't magically make Java able to understand the VB6 format.


That is what I'm asking.

2) Find the specs for that format and write your own deserialization code.

What did you mean by that? I thought you meant if I knew the code in the VB file, I would be able to do it.

How am I able to read a VB6 file? Is it possible? Nothing on google at all, this question itself is on Google's first page...

I saw something called CORBA that had to do with mixing coding platforms, though I'm not sure if that will work...
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 12983

Jay Orsaw wrote:That is what I'm asking.

2) Find the specs for that format and write your own deserialization code.

What did you mean by that? I thought you meant if I knew the code in the VB file, I would be able to do it.

How am I able to read a VB6 file? Is it possible? Nothing on google at all, this question itself is on Google's first page...


There's no such thing as "a VB6 file". Or rather, VB code can write anything it likes into a file. So for example it might write a 32-character string followed by two integer values (at four bytes each). Or it might write a long integer value (eight bytes) followed by a single character followed by a short integer value (two bytes). The possibilities are endless. So what you have to do -- as already stated -- is to find out what is in that file. How it is structured. The format of the file, in other words. The answer is going to be something like one of the two examples I just mentioned, only probably more complicated than that.

If you don't have anybody to tell you what the format is then you're probably out of luck. Unless you have a copy of the code which produces the file, in which case you might have a chance at figuring it out.
Jay Orsaw
Ranch Hand

Joined: Jun 14, 2011
Posts: 54
Paul Clapham wrote:
Jay Orsaw wrote:That is what I'm asking.

2) Find the specs for that format and write your own deserialization code.

What did you mean by that? I thought you meant if I knew the code in the VB file, I would be able to do it.

How am I able to read a VB6 file? Is it possible? Nothing on google at all, this question itself is on Google's first page...


There's no such thing as "a VB6 file". Or rather, VB code can write anything it likes into a file. So for example it might write a 32-character string followed by two integer values (at four bytes each). Or it might write a long integer value (eight bytes) followed by a single character followed by a short integer value (two bytes). The possibilities are endless. So what you have to do -- as already stated -- is to find out what is in that file. How it is structured. The format of the file, in other words. The answer is going to be something like one of the two examples I just mentioned, only probably more complicated than that.

If you don't have anybody to tell you what the format is then you're probably out of luck. Unless you have a copy of the code which produces the file, in which case you might have a chance at figuring it out.


thank you, as I have already mentioned I HAVE THE FILE, now what do I do with it? I have the format and I made it into a class but the problem is I cannot read it in with the objectinputsteam, as stated above I get an error. What should I do to read in the file since the OIS isn't working?

There are 3 TYPES each type has a set of objects like "String" for example. I set up the first TYPE as 1 class called planHead(Same as in the Vb code in the file..) But as you can see in the problem above I am stuck at reading in the file to try and deserialize it, so that's why I ask if there is a different way to read it in..?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 12983

Jay Orsaw wrote:thank you, as I have already mentioned I HAVE THE FILE, now what do I do with it? I have the format and I made it into a class but the problem is I cannot read it in with the objectinputsteam, as stated above I get an error. What should I do to read in the file since the OIS isn't working?

There are 3 TYPES each type has a set of objects like "String" for example. I set up the first TYPE as 1 class called planHead(Same as in the Vb code in the file..) But as you can see in the problem above I am stuck at reading in the file to try and deserialize it, so that's why I ask if there is a different way to read it in..?


I guess this hasn't been explicitly stated, so let me start by pointing out that you can't use Java serialization, because that isn't how the file is formatted.

But you have the specs about what is in the file (right? That was what you meant when you said you "have the format", was it?) so the next step is to write some Java code which reads the file. If the specs include binary data which corresponds to Java types then you could use a DataInputStream to read that data.
Jeff Verdegan
Rancher

Joined: Jan 03, 2004
Posts: 1513
Jay Orsaw wrote:
Jeff Verdegan wrote:
Jay Orsaw wrote:
The error appears when reading the file... hmmm...


What file? Are you trying to read the VB6 file with Java's ObjectInputStream? You can't do that. That would only work if Java's serialization format was the same as that VB6 format, which is phenomenally unlikely. Just writing a Java class that's the structural equivalent of the VB6 class doesn't magically make Java able to understand the VB6 format.


That is what I'm asking.

2) Find the specs for that format and write your own deserialization code.

What did you mean by that? I thought you meant if I knew the code in the VB file, I would be able to do it.


By "specs" I didn't mean the VB6 source file that corresponds to the binary serialized version. I mean the specification for the format of how a class or object or whatever is serialized for that file you're trying to read. For instance, the format might be "First 2 bytes indicate the number of objects. Next 2 bytes indicate the length of the class name of the first object. Then whatever number those 2 bytes represent, that many bytes are the characters for that class name," and so on. Or it could be something totally different. You would need to learn that format, and write code to read and interpret those bytes accordingly. (Or find a library that already does that.)

How am I able to read a VB6 file? Is it possible?


Of course it's possible. If you know the format, or have a library that does.
Jeff Verdegan
Rancher

Joined: Jan 03, 2004
Posts: 1513
Paul Clapham wrote:
I guess this hasn't been explicitly stated, so let me start by pointing out that you can't use Java serialization, because that isn't how the file is formatted.


I thought I was pretty explicit about that...

me wrote:Java's serialization mechanism is also binary, but that doesn't mean it can read any of those other formats or whatever format your VB files use.

me wrote:That would only work if Java's serialization format was the same as that VB6 format, which is phenomenally unlikely.


Okay, so I guess that's not quite as explicit as saying "you can't use Java serialization". My bad.

This message was edited 1 time. Last update was at by Jeff Verdegan

Jeff Verdegan
Rancher

Joined: Jan 03, 2004
Posts: 1513
Jay Orsaw wrote:
thank you, as I have already mentioned I HAVE THE FILE, now what do I do with it?


You do some research. You first find out if there's a Java library you can use that knows how to read that format. If you can't find one, then you find the specs for that format to find out how it converts a VB6 class or object into that particular binary representation.

I have the format and I made it into a class


What exactly is that supposed to mean?
Jay Orsaw
Ranch Hand

Joined: Jun 14, 2011
Posts: 54
Paul Clapham wrote:
Jay Orsaw wrote:thank you, as I have already mentioned I HAVE THE FILE, now what do I do with it? I have the format and I made it into a class but the problem is I cannot read it in with the objectinputsteam, as stated above I get an error. What should I do to read in the file since the OIS isn't working?

There are 3 TYPES each type has a set of objects like "String" for example. I set up the first TYPE as 1 class called planHead(Same as in the Vb code in the file..) But as you can see in the problem above I am stuck at reading in the file to try and deserialize it, so that's why I ask if there is a different way to read it in..?


I guess this hasn't been explicitly stated, so let me start by pointing out that you can't use Java serialization, because that isn't how the file is formatted.

But you have the specs about what is in the file (right? That was what you meant when you said you "have the format", was it?) so the next step is to write some Java code which reads the file. If the specs include binary data which corresponds to Java types then you could use a DataInputStream to read that data.


Thank you the DataInputStream worked, only issue is that when I use the VB "Single" with the Java "Float" I get a # like 2.40239E-41 when it should be 3.0. If I read in 2 characters from the stream and then do the float I get 3.0, but when I try to do that with the next float which should be 4.0, I cannot, and I doubt that even makes sense to read in the 2 extra characters...











Everything else works fine except for this float... Even reading data after the misread floats, was successful. The joys of multiple languages... BOO!!! Java forever!

This message was edited 2 times. Last update was at by Jay Orsaw

Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 12983

What you are now doing is called "reverse engineering". A tedious technique but probably the only one available at this point in time.

You may find that looking at the hexadecimal representation of data in the file helps. For this you can use a tool called a "hex editor". You'll find plenty of them available on the internet.
Jeff Verdegan
Rancher

Joined: Jan 03, 2004
Posts: 1513
Jay Orsaw wrote:Thank you the DataInputStream worked, only issue is that when I use the VB "Single" with the Java "Float" I get a # like 2.40239E-41 when it should be 3.0.


I wouldn't call that "working". This means that the serialization format for a Java float is not the same as it is for a VB Single.

If I read in 2 characters from the stream and then do the float I get 3.0, but when I try to do that with the next float which should be 4.0, I cannot, and I doubt that even makes sense to read in the 2 extra characters...


No, it ceratinly doesn't make sense. It doesn't make sense to read any characters at all when reading a float. A float consists of bytes, not characters.

Everything else works fine except for this float... Even reading data after the misread floats, was successful. The joys of multiple languages... BOO!!! Java forever!


The problem is not multiple languages. The problem is that you're still assuming that two totally separate, independent entities would take identical approaches to a given problem.

Also, I wouldn't get too excited yet about other stuff working. The fact that it happened to work for whatever tests you ran doesn't mean it will work for all cases on those types. There may be some overlap, even with different formats. You still need to find out the specs for the format and see if they match the specs for Java's primitive serialization. If that information is not available to you, then you'll need to to some very thorough testing to include corner cases, minimums, maximums, etc.

This message was edited 1 time. Last update was at by Jeff Verdegan

Jay Orsaw
Ranch Hand

Joined: Jun 14, 2011
Posts: 54
Paul Clapham wrote:What you are now doing is called "reverse engineering". A tedious technique but probably the only one available at this point in time.

You may find that looking at the hexadecimal representation of data in the file helps. For this you can use a tool called a "hex editor". You'll find plenty of them available on the internet.


Thanks, but I feel like I'm not clear. I have all of the VB code, I have the VB file, I am just having a problem reading this float(VB single). I can read the other things in order no problem, the float is giving me the issue. Int(VB Long) Boolean, etc all work, just this floating point # is giving me a random number... There is nothing between the BOOLEAN and the FLOAT, but the only way to actually get 3.0 is by throwing out 2 characters, and then reading the float, which makes no sense since they are right after another. I'm not sure how I'm "reverse engineering" since I have everything needed, I just need Java to be able to work for it...


it goes 2 Strings, 1 boolean, 2 floats, 2 ints, ETC. The fact I can read in the 2 strings, the 1 boolean, the 2 floats(wrong values) and then getting the CORRECT 2 int values next is weird.
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 2174

Jay Orsaw wrote:it goes 2 Strings, 1 boolean, 2 floats, 2 ints, ETC. The fact I can read in the 2 strings, the 1 boolean, the 2 floats(wrong values) and then getting the CORRECT 2 int values next is weird.


My best guess is that Java uses a different encoding of float to bits than VB uses. But they must both use the same number of bits for a float, which is why the following data is still unaffected.

A bit of digging in the Javadocs suggests that Java will read floats according to the format specified in Float.intToFloatBits:
Returns the float value corresponding to a given bit representation. The argument is considered to be a representation of a floating-point value according to the IEEE 754 floating-point "single format" bit layout.

(more details given if you follow the link).

You need to find the equivalent specification for what VB uses. You may then have to read the bytes directly, and manipulate them yourself, rather than relying on the Java library to do it for you.

This message was edited 2 times. Last update was at by Matthew Brown

Jeff Verdegan
Rancher

Joined: Jan 03, 2004
Posts: 1513
Jay Orsaw wrote:I can read the other things in order no problem


Because those things coincidentally happen to be the same in that VB6 format is in Java's format. (For the handful of values that you have tested.)

It's like you're listening to somebody speak Spanish, and you hear him say the word "no", and you say, "I understood 'no', so why can't I understand the rest of what he's saying?"

this floating point # is giving me a random number...


No, it is giving you the interpretation of those bytes according to Java's format for float, which, obviously, is different from VB's format for Single.

There is nothing between the BOOLEAN and the FLOAT, but the only way to actually get 3.0 is by throwing out 2 characters,


That happened to appear work for the few values you happened to test. Probably those bytes are important in general but didn't happen to be used in your particular test values.

I'm not sure how I'm "reverse engineering" since I have everything needed,


No, you don't have everything you need. You don't have the spec. You're reverse engineering because you're looking at the final result and the known input that generated it and trying to find patterns that you can use to deduce the rules of how the input gets translated to the final result. Or maybe you're not doing that. I'm starting to think you're just trying stuff and hoping for the best and getting lucky that some things happen to work, but not actually understanding how or why they work (that is, not knowing anything about the formats involved).

I just need Java to be able to work for it...


Java is not the problem. Java will work fine for this. Once you figure out the actual format and write the appropriate Java code to translate it.

 
 
subject: Deserializing Visual Basic 6 files in Java?
 
Threads others viewed
Using Serialize to hold login info
Serializable
Openconnection ,readobject,writeobject,errors,quesition
best way to compress in GZIP serialized objects in MEMORY
problem while moving the java project from windows environment to FreeBSD in ASCII mode.
developer file tools

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture