mirror of
https://github.com/revanced/Apktool.git
synced 2025-06-12 21:27:36 +02:00
Moving all REPOs into one
This commit is contained in:
62
brut.j.util/src/main/java/brut/util/BrutIO.java
Normal file
62
brut.j.util/src/main/java/brut/util/BrutIO.java
Normal file
@ -0,0 +1,62 @@
|
||||
/**
|
||||
* Copyright 2010 Ryszard Wiśniewski <brut.alll@gmail.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package brut.util;
|
||||
|
||||
import java.io.*;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
|
||||
/**
|
||||
* @author Ryszard Wiśniewski <brut.alll@gmail.com>
|
||||
*/
|
||||
public class BrutIO {
|
||||
public static void copyAndClose(InputStream in, OutputStream out)
|
||||
throws IOException {
|
||||
try {
|
||||
IOUtils.copy(in, out);
|
||||
} finally {
|
||||
try {
|
||||
in.close();
|
||||
out.close();
|
||||
} catch (IOException ex) {}
|
||||
}
|
||||
}
|
||||
|
||||
public static long recursiveModifiedTime(File[] files) {
|
||||
long modified = 0;
|
||||
for (int i = 0; i < files.length; i++) {
|
||||
long submodified = recursiveModifiedTime(files[i]);
|
||||
if (submodified > modified) {
|
||||
modified = submodified;
|
||||
}
|
||||
}
|
||||
return modified;
|
||||
}
|
||||
|
||||
public static long recursiveModifiedTime(File file) {
|
||||
long modified = file.lastModified();
|
||||
if (file.isDirectory()) {
|
||||
File[] subfiles = file.listFiles();
|
||||
for (int i = 0; i < subfiles.length; i++) {
|
||||
long submodified = recursiveModifiedTime(subfiles[i]);
|
||||
if (submodified > modified) {
|
||||
modified = submodified;
|
||||
}
|
||||
}
|
||||
}
|
||||
return modified;
|
||||
}
|
||||
}
|
91
brut.j.util/src/main/java/brut/util/DataInputDelegate.java
Normal file
91
brut.j.util/src/main/java/brut/util/DataInputDelegate.java
Normal file
@ -0,0 +1,91 @@
|
||||
/**
|
||||
* Copyright 2010 Ryszard Wiśniewski <brut.alll@gmail.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package brut.util;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author Ryszard Wiśniewski <brut.alll@gmail.com>
|
||||
*/
|
||||
abstract public class DataInputDelegate implements DataInput {
|
||||
protected final DataInput mDelegate;
|
||||
|
||||
public DataInputDelegate(DataInput delegate) {
|
||||
this.mDelegate = delegate;
|
||||
}
|
||||
|
||||
public int skipBytes(int n) throws IOException {
|
||||
return mDelegate.skipBytes(n);
|
||||
}
|
||||
|
||||
public int readUnsignedShort() throws IOException {
|
||||
return mDelegate.readUnsignedShort();
|
||||
}
|
||||
|
||||
public int readUnsignedByte() throws IOException {
|
||||
return mDelegate.readUnsignedByte();
|
||||
}
|
||||
|
||||
public String readUTF() throws IOException {
|
||||
return mDelegate.readUTF();
|
||||
}
|
||||
|
||||
public short readShort() throws IOException {
|
||||
return mDelegate.readShort();
|
||||
}
|
||||
|
||||
public long readLong() throws IOException {
|
||||
return mDelegate.readLong();
|
||||
}
|
||||
|
||||
public String readLine() throws IOException {
|
||||
return mDelegate.readLine();
|
||||
}
|
||||
|
||||
public int readInt() throws IOException {
|
||||
return mDelegate.readInt();
|
||||
}
|
||||
|
||||
public void readFully(byte[] b, int off, int len) throws IOException {
|
||||
mDelegate.readFully(b, off, len);
|
||||
}
|
||||
|
||||
public void readFully(byte[] b) throws IOException {
|
||||
mDelegate.readFully(b);
|
||||
}
|
||||
|
||||
public float readFloat() throws IOException {
|
||||
return mDelegate.readFloat();
|
||||
}
|
||||
|
||||
public double readDouble() throws IOException {
|
||||
return mDelegate.readDouble();
|
||||
}
|
||||
|
||||
public char readChar() throws IOException {
|
||||
return mDelegate.readChar();
|
||||
}
|
||||
|
||||
public byte readByte() throws IOException {
|
||||
return mDelegate.readByte();
|
||||
}
|
||||
|
||||
public boolean readBoolean() throws IOException {
|
||||
return mDelegate.readBoolean();
|
||||
}
|
||||
}
|
56
brut.j.util/src/main/java/brut/util/Duo.java
Normal file
56
brut.j.util/src/main/java/brut/util/Duo.java
Normal file
@ -0,0 +1,56 @@
|
||||
/**
|
||||
* Copyright 2010 Ryszard Wiśniewski <brut.alll@gmail.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package brut.util;
|
||||
|
||||
/**
|
||||
* @author Ryszard Wiśniewski <brut.alll@gmail.com>
|
||||
*/
|
||||
public class Duo<T1, T2> {
|
||||
public final T1 m1;
|
||||
public final T2 m2;
|
||||
|
||||
public Duo(T1 t1, T2 t2) {
|
||||
this.m1 = t1;
|
||||
this.m2 = t2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
final Duo<T1, T2> other = (Duo<T1, T2>) obj;
|
||||
if (this.m1 != other.m1 && (this.m1 == null || !this.m1.equals(other.m1))) {
|
||||
return false;
|
||||
}
|
||||
if (this.m2 != other.m2 && (this.m2 == null || !this.m2.equals(other.m2))) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 3;
|
||||
hash = 71 * hash + (this.m1 != null ? this.m1.hashCode() : 0);
|
||||
hash = 71 * hash + (this.m2 != null ? this.m2.hashCode() : 0);
|
||||
return hash;
|
||||
}
|
||||
}
|
85
brut.j.util/src/main/java/brut/util/ExtDataInput.java
Normal file
85
brut.j.util/src/main/java/brut/util/ExtDataInput.java
Normal file
@ -0,0 +1,85 @@
|
||||
/**
|
||||
* Copyright 2010 Ryszard Wiśniewski <brut.alll@gmail.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package brut.util;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
* @author Ryszard Wiśniewski <brut.alll@gmail.com>
|
||||
*/
|
||||
public class ExtDataInput extends DataInputDelegate {
|
||||
public ExtDataInput(InputStream in) {
|
||||
this((DataInput) new DataInputStream(in));
|
||||
}
|
||||
|
||||
public ExtDataInput(DataInput delegate) {
|
||||
super(delegate);
|
||||
}
|
||||
|
||||
public int[] readIntArray(int length) throws IOException {
|
||||
int[] array = new int[length];
|
||||
for(int i = 0; i < length; i++) {
|
||||
array[i] = readInt();
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
public void skipInt() throws IOException {
|
||||
skipBytes(4);
|
||||
}
|
||||
|
||||
public void skipCheckInt(int expected) throws IOException {
|
||||
int got = readInt();
|
||||
if (got != expected) {
|
||||
throw new IOException(String.format(
|
||||
"Expected: 0x%08x, got: 0x%08x", expected, got));
|
||||
}
|
||||
}
|
||||
|
||||
public void skipCheckShort(short expected) throws IOException {
|
||||
short got = readShort();
|
||||
if (got != expected) {
|
||||
throw new IOException(String.format(
|
||||
"Expected: 0x%08x, got: 0x%08x", expected, got));
|
||||
}
|
||||
}
|
||||
|
||||
public void skipCheckByte(byte expected) throws IOException {
|
||||
byte got = readByte();
|
||||
if (got != expected) {
|
||||
throw new IOException(String.format(
|
||||
"Expected: 0x%08x, got: 0x%08x", expected, got));
|
||||
}
|
||||
}
|
||||
|
||||
public String readNulEndedString(int length, boolean fixed)
|
||||
throws IOException {
|
||||
StringBuilder string = new StringBuilder(16);
|
||||
while(length-- != 0) {
|
||||
short ch = readShort();
|
||||
if (ch == 0) {
|
||||
break;
|
||||
}
|
||||
string.append((char) ch);
|
||||
}
|
||||
if (fixed) {
|
||||
skipBytes(length * 2);
|
||||
}
|
||||
|
||||
return string.toString();
|
||||
}
|
||||
}
|
82
brut.j.util/src/main/java/brut/util/Jar.java
Normal file
82
brut.j.util/src/main/java/brut/util/Jar.java
Normal file
@ -0,0 +1,82 @@
|
||||
/**
|
||||
* Copyright 2010 Ryszard Wiśniewski <brut.alll@gmail.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package brut.util;
|
||||
|
||||
import brut.common.BrutException;
|
||||
import java.io.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
|
||||
/**
|
||||
* @author Ryszard Wiśniewski <brut.alll@gmail.com>
|
||||
*/
|
||||
abstract public class Jar {
|
||||
private final static Set<String> mLoaded = new HashSet<String>();
|
||||
private final static Map<String, File> mExtracted =
|
||||
new HashMap<String, File>();
|
||||
|
||||
public static File getResourceAsFile(String name) throws BrutException {
|
||||
File file = mExtracted.get(name);
|
||||
if (file == null) {
|
||||
file = extractToTmp(name);
|
||||
mExtracted.put(name, file);
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
||||
public static void load(String libPath) {
|
||||
if (mLoaded.contains(libPath)) {
|
||||
return;
|
||||
}
|
||||
|
||||
File libFile;
|
||||
try {
|
||||
libFile = getResourceAsFile(libPath);
|
||||
} catch (BrutException ex) {
|
||||
throw new UnsatisfiedLinkError(ex.getMessage());
|
||||
}
|
||||
|
||||
System.load(libFile.getAbsolutePath());
|
||||
}
|
||||
|
||||
public static File extractToTmp(String resourcePath) throws BrutException {
|
||||
return extractToTmp(resourcePath, "brut_util_Jar_");
|
||||
}
|
||||
|
||||
public static File extractToTmp(String resourcePath, String tmpPrefix)
|
||||
throws BrutException {
|
||||
try {
|
||||
InputStream in = Class.class.getResourceAsStream(resourcePath);
|
||||
if (in == null) {
|
||||
throw new FileNotFoundException(resourcePath);
|
||||
}
|
||||
File fileOut = File.createTempFile(tmpPrefix, null);
|
||||
fileOut.deleteOnExit();
|
||||
OutputStream out = new FileOutputStream(fileOut);
|
||||
IOUtils.copy(in, out);
|
||||
in.close();
|
||||
out.close();
|
||||
return fileOut;
|
||||
} catch (IOException ex) {
|
||||
throw new BrutException(
|
||||
"Could not extract resource: " + resourcePath, ex);
|
||||
}
|
||||
}
|
||||
}
|
138
brut.j.util/src/main/java/brut/util/OS.java
Normal file
138
brut.j.util/src/main/java/brut/util/OS.java
Normal file
@ -0,0 +1,138 @@
|
||||
/**
|
||||
* Copyright 2010 Ryszard Wiśniewski <brut.alll@gmail.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package brut.util;
|
||||
|
||||
import brut.common.BrutException;
|
||||
import java.io.*;
|
||||
import java.util.Arrays;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
|
||||
/**
|
||||
* @author Ryszard Wiśniewski <brut.alll@gmail.com>
|
||||
*/
|
||||
public class OS {
|
||||
public static void rmdir(File dir) throws BrutException {
|
||||
if (! dir.exists()) {
|
||||
return;
|
||||
}
|
||||
File[] files = dir.listFiles();
|
||||
for (int i = 0; i < files.length; i++) {
|
||||
File file = files[i];
|
||||
if (file.isDirectory()) {
|
||||
rmdir(file);
|
||||
} else {
|
||||
file.delete();
|
||||
}
|
||||
}
|
||||
dir.delete();
|
||||
}
|
||||
|
||||
public static void rmdir(String dir) throws BrutException {
|
||||
rmdir(new File(dir));
|
||||
}
|
||||
|
||||
public static void cpdir(File src, File dest) throws BrutException {
|
||||
dest.mkdirs();
|
||||
File[] files = src.listFiles();
|
||||
for (int i = 0; i < files.length; i++) {
|
||||
File file = files[i];
|
||||
File destFile = new File(dest.getPath() + File.separatorChar
|
||||
+ file.getName());
|
||||
if (file.isDirectory()) {
|
||||
cpdir(file, destFile);
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
InputStream in = new FileInputStream(file);
|
||||
OutputStream out = new FileOutputStream(destFile);
|
||||
IOUtils.copy(in, out);
|
||||
in.close();
|
||||
out.close();
|
||||
} catch (IOException ex) {
|
||||
throw new BrutException("Could not copy file: " + file, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void cpdir(String src, String dest) throws BrutException {
|
||||
cpdir(new File(src), new File(dest));
|
||||
}
|
||||
|
||||
public static void exec(String[] cmd) throws BrutException {
|
||||
Process ps = null;
|
||||
try {
|
||||
ps = Runtime.getRuntime().exec(cmd);
|
||||
|
||||
new StreamForwarder(ps.getInputStream(), System.err).start();
|
||||
new StreamForwarder(ps.getErrorStream(), System.err).start();
|
||||
if (ps.waitFor() != 0) {
|
||||
throw new BrutException(
|
||||
"could not exec command: " + Arrays.toString(cmd));
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
throw new BrutException(
|
||||
"could not exec command: " + Arrays.toString(cmd), ex);
|
||||
} catch (InterruptedException ex) {
|
||||
throw new BrutException(
|
||||
"could not exec command: " + Arrays.toString(cmd), ex);
|
||||
}
|
||||
}
|
||||
|
||||
public static File createTempDirectory() throws BrutException {
|
||||
try {
|
||||
File tmp = File.createTempFile("BRUT", null);
|
||||
if (!tmp.delete()) {
|
||||
throw new BrutException("Could not delete tmp file: " + tmp.getAbsolutePath());
|
||||
}
|
||||
if (!tmp.mkdir()) {
|
||||
throw new BrutException("Could not create tmp dir: " + tmp.getAbsolutePath());
|
||||
}
|
||||
return tmp;
|
||||
} catch (IOException ex) {
|
||||
throw new BrutException("Could not create tmp dir", ex);
|
||||
}
|
||||
}
|
||||
|
||||
static class StreamForwarder extends Thread {
|
||||
|
||||
public StreamForwarder(InputStream in, OutputStream out) {
|
||||
mIn = in;
|
||||
mOut = out;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
BufferedReader in = new BufferedReader(
|
||||
new InputStreamReader(mIn));
|
||||
BufferedWriter out = new BufferedWriter(
|
||||
new OutputStreamWriter(mOut));
|
||||
String line;
|
||||
while ((line = in.readLine()) != null) {
|
||||
out.write(line);
|
||||
out.newLine();
|
||||
}
|
||||
out.flush();
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private final InputStream mIn;
|
||||
private final OutputStream mOut;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user