Remove symlinks and update dbip to 2021_12

This commit is contained in:
emanuele-f
2021-12-14 11:42:55 +01:00
parent fd9f8a4cbd
commit a924ee5073
7 changed files with 15 additions and 14 deletions
+2 -2
View File
@@ -7,8 +7,8 @@
[submodule "submodules/libpcap"]
path = submodules/libpcap
url = https://github.com/the-tcpdump-group/libpcap
[submodule "submodules/res"]
path = submodules/res
[submodule "app/src/main/res/raw"]
path = app/src/main/res/raw
url = https://github.com/emanuele-f/PCAPdroid_res
[submodule "submodules/MaxMind-DB-Reader-java"]
path = submodules/MaxMind-DB-Reader-java
+4
View File
@@ -48,6 +48,10 @@ android {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
sourceSets {
main.java.srcDirs += '../submodules/MaxMind-DB-Reader-java/src/main/java'
}
}
dependencies {
@@ -30,9 +30,7 @@ import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.InetAddress;
import java.util.zip.GZIPInputStream;
/* A class to query geolocation info from IP addresses. */
public class Geolocation {
@@ -63,12 +61,12 @@ public class Geolocation {
private void openDb() {
try {
File countryFile = new File(mContext.getCacheDir() + "/dbip_country_lite.mmdb");
ungzip(R.raw.dbip_country_lite_2021_11_mmdb_gz, countryFile);
res_to_file(R.raw.dbip_country_lite, countryFile);
mCountryReader = new Reader(countryFile);
Log.d(TAG, "Country DB loaded: " + mCountryReader.getMetadata());
File asnFile = new File(mContext.getCacheDir() + "/dbip_asn_lite.mmdb");
ungzip(R.raw.dbip_asn_lite_2021_11_mmdb_gz, asnFile);
res_to_file(R.raw.dbip_asn_lite, asnFile);
mAsnReader = new Reader(asnFile);
Log.d(TAG, "ASN DB loaded: " + mAsnReader.getMetadata());
} catch (IOException e) {
@@ -77,13 +75,14 @@ public class Geolocation {
}
}
private void ungzip(int resid, File dst) throws IOException {
try(InputStream is = new GZIPInputStream(mContext.getResources().openRawResource(resid))) {
// We need to get a File from the resource so that the Reader can mmap it
private void res_to_file(int resid, File dst) throws IOException {
try(InputStream is = mContext.getResources().openRawResource(resid)) {
try(BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(dst))) {
byte[] bytesIn = new byte[4096];
int read = 0;
int read;
while ((read = is.read(bytesIn)) != -1)
while((read = is.read(bytesIn)) != -1)
bos.write(bytesIn, 0, read);
}
}
-1
View File
@@ -1 +0,0 @@
../../../../../submodules/MaxMind-DB-Reader-java/src/main/java/com/maxmind
+1 -1
View File
@@ -241,7 +241,7 @@ void hexdump(const char *buf, size_t bufsize) {
if((off % 16) != 0) {
out[idx] = '\0';
log_d("%s", out);
idx = sprintf(out, "%06x", off);
idx = sprintf(out, "%06zx", off);
}
out[idx] = '\0';
-1
View File
@@ -1 +0,0 @@
../../../../submodules/res/raw
Submodule submodules/res deleted from 64a2e49b6a