You should take a look at our existing "Java Class" rule (BC2) or the "Java class to source" file format (BC3), which does the same thing with the JAD decompiler. The BC3 bcpkg files are just renamed zips.
In both cases they use a one-line batch file to handle the piping. That is, the "External Conversion" command is "jad.bat %s %s" and the batch file is "jad.exe -p %1 > %2". To pipe into stdin you just use the "<" symbol. If you're using the Linux build the batch file isn't necessary because the external conversion command is run through the shell first, so it does support the command line piping syntax.
Announcement
Collapse
No announcement yet.
File Format conversion via pipes instead of tempory files
Collapse
X
-
File Format conversion via pipes instead of tempory files
Hello
I have been working on creating a file format converter for dissassmbing java .class files into jasmin assembly language so that I can see how different two java classes are. I have been using the d-java program for that, however the program always writes the disassembled output to stdout, and there is no option in BC3 to capture stdout instead of using an output file, so I had to create a perl wrapper script:
Code:#!/bin/perl use File::Copy; use File::Basename; my ($src, $dest) = @ARGV; open DEBUGOUT, '>>', 'C:\\Program Files\\d-java\\d-java_DEBUG.txt'; print DEBUGOUT "Args:\n\tsrc = $src\n\tdest = $dest\n"; # Copy the src file to .class so that the dissasmber will load it. my ($name,$path,$suffix) = fileparse($src, qr/\.[^.]*/); my $newName = $path.$name.'.class'; copy $src, $newName; print DEBUGOUT "\t$src coppied to $newName\n"; chdir "C:/Program Files/d-java"; my $cmd = sprintf 'D-Java.exe -e C:\\Temp\\d-java_DEBUG.log -o jasmin -n lvt -n lnt "%s"', $newName; print DEBUGOUT "\tDissaembly command: \"$cmd\"\n"; open CMDOUT, '-|', $cmd or die "Error running d-java dissassember $!"; my @jasminLines = <CMDOUT>; close CMDOUT; printf DEBUGOUT "\t%d lines of jasmin disassmbly produced\n", scalar @jasminLines; open OUTFILE, '>', $dest or die "Error writing output to $dest $!"; print OUTFILE @jasminLines; close OUTFILE; print DEBUGOUT "Written to $dest\n\n"; close DEBUGOUT;
You can also see in the above program that I had to create a copy of the input file with the correct extension. This is because if the input is passed to d-java as a file rather than a pipe, it will only convert files with a .class extension, and because I was comparing files in an archive (a java .jar file). BC3 had to extract a copy which got a .tmp extension.Tags: None
Leave a comment: