Download的源代码和Marco Schmidt's jpegextractor的字节码。
这适用于 jpg。
对于png,
将copyJpeg 函数替换为
private void copypng(InputStream in, OutputStream out) throws
IOException
{
boolean notFinished = true;
long copiedBytes = 3;
do
{
int v1 = in.read();
if (v1 == 0x89) // marker
{
int v2 = in.read();
if (v2 < 0) // end of file
{
out.write(0x82);
copiedBytes++;
notFinished = false;
}
else
if (v2 == 0x49) // embedded png stream ended
{
// copy the end of stream marker
out.write(0x49);
out.write(0x45);
out.write(0x4E);
out.write(0x44);
out.write(0xAE);
out.write(0x42);
out.write(0x60);
out.write(0x82);
copiedBytes += 2;
notFinished = false;
}
else
{
// copy the two bytes, just a marker of the embedded png
out.write(0x89);
out.write(v2);
copiedBytes += 2;
}
}
else
if (v1 == -1) // unexpected end of input file
{
notFinished = false;
}
else // just copy that value
{
out.write(v1);
copiedBytes++;
}
}
while (notFinished);
totalBytes += copiedBytes;
if (!quiet)
{
System.out.println(" (" + copiedBytes + " bytes)");
}
totalOutputFiles++;
// close output stream
try
{
out.close();
}
catch (IOException ioe)
{
// ignore error when closing output stream
}
}
并将process(InputStream in)替换为
private void process(InputStream in) throws
IOException
{
int v1;
do
{
v1 = in.read();
if (v1 == 0x89)
{
int v2 = in.read();
if (v2 == 0x50)
{
int v3 = in.read();
if (v3 == 0x4E)
{
int v4 = in.read();
if (v4 == 0x47)
{
int v5 = in.read();
if (v5 == 0x0D)
{
int v6 = in.read();
if (v6 == 0x0A)
{
int v7 = in.read();
if (v7 == 0x1A)
{
int v8 = in.read();
if (v8 == 0x0A)
{
OutputStream out = createNextOutputStream();
out.write(v1);
out.write(v2);
out.write(v3);
out.write(v4);
out.write(v5);
out.write(v6);
out.write(v7);
out.write(v8);
copypng(in, out);
}
}
}
}
}
}
}
}
}
while (v1 != -1);
}
对于 gif,
将copyJpeg 函数替换为
private void copygif(InputStream in, OutputStream out) throws
IOException
{
boolean notFinished = true;
long copiedBytes = 3;
do
{
int v1 = in.read();
if (v1 == 0x47) // marker
{
int v2 = in.read();
if (v2 < 0) // end of file
{
out.write(0x00);
copiedBytes++;
notFinished = false;
}
else
if (v2 == 0x21) // embedded png stream ended
{
// copy the end of stream marker
out.write(0x21);
out.write(0x00);
out.write(0x00);
out.write(0x3B);
out.write(0x00);
copiedBytes += 2;
notFinished = false;
}
else
{
// copy the two bytes, just a marker of the embedded png
out.write(0x47);
out.write(v2);
copiedBytes += 2;
}
}
else
if (v1 == -1) // unexpected end of input file
{
notFinished = false;
}
else // just copy that value
{
out.write(v1);
copiedBytes++;
}
}
while (notFinished);
totalBytes += copiedBytes;
if (!quiet)
{
System.out.println(" (" + copiedBytes + " bytes)");
}
totalOutputFiles++;
// close output stream
try
{
out.close();
}
catch (IOException ioe)
{
// ignore error when closing output stream
}
}
将process(InputStream in)替换为
private void process(InputStream in) throws
IOException
{
int v1;
do
{
v1 = in.read();
if (v1 == 0x47)
{
int v2 = in.read();
if (v2 == 0x49)
{
int v3 = in.read();
if (v3 == 0x46)
{
int v4 = in.read();
if (v4 == 0x38)
{
int v5 = in.read();
if (v5 == 0x39)
{
int v6 = in.read();
if (v6 == 0x61)
{
OutputStream out = createNextOutputStream();
out.write(v1);
out.write(v2);
out.write(v3);
out.write(v4);
out.write(v5);
out.write(v6);
copygif(in, out);
}
}
}
}
}
}
}
while (v1 != -1);
}
并更新private void setDefaultArguments()中outputSuffix的值