mirror of
https://github.com/emanuele-f/PCAPdroid.git
synced 2026-07-06 21:11:15 +08:00
parent
fe5e53e8e4
commit
cdafc69902
@ -22,7 +22,6 @@ package com.emanuelef.remote_capture;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.core.app.NotificationManagerCompat;
|
||||
|
||||
|
||||
@ -23,7 +23,6 @@ import android.annotation.SuppressLint;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
@ -147,4 +146,4 @@ public class AppsLoader implements LoaderManager.LoaderCallbacks<ArrayList<AppDe
|
||||
runLoader(OPERATION_LOAD_APPS_INFO, null);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -24,7 +24,6 @@ import android.content.Context;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.util.Log;
|
||||
import android.util.SparseArray;
|
||||
|
||||
import com.emanuelef.remote_capture.interfaces.DrawableLoader;
|
||||
|
||||
@ -23,7 +23,6 @@ import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Build;
|
||||
import android.provider.Settings;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.preference.PreferenceManager;
|
||||
|
||||
|
||||
@ -22,7 +22,6 @@ package com.emanuelef.remote_capture;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.util.ArrayMap;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.collection.ArraySet;
|
||||
import androidx.preference.PreferenceManager;
|
||||
@ -192,7 +191,7 @@ public class Blacklists {
|
||||
if(files != null) {
|
||||
for(File f: files) {
|
||||
if(!validLists.contains(f)) {
|
||||
Log.d(TAG, "Removing unknown list: " + f.getPath());
|
||||
Log.i(TAG, "Removing unknown list: " + f.getPath());
|
||||
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
f.delete();
|
||||
@ -214,11 +213,11 @@ public class Blacklists {
|
||||
bl.setUpdating();
|
||||
notifyListeners();
|
||||
|
||||
Log.d(TAG, "Updating " + mLists.size() + " blacklists...");
|
||||
Log.i(TAG, "Updating " + mLists.size() + " blacklists...");
|
||||
mFirstUpdate = false;
|
||||
|
||||
for(BlacklistDescriptor bl: mLists) {
|
||||
Log.d(TAG, "\tupdating " + bl.fname + "...");
|
||||
Log.i(TAG, "\tupdating " + bl.fname + "...");
|
||||
|
||||
if(Utils.downloadFile(bl.url, getListPath(bl)))
|
||||
bl.setUpdated(System.currentTimeMillis());
|
||||
@ -275,7 +274,7 @@ public class Blacklists {
|
||||
}
|
||||
}
|
||||
|
||||
Log.d(TAG, "Blacklists loaded: " + num_loaded + " lists, " + num_domains + " domains, " + num_ips + " IPs");
|
||||
Log.i(TAG, "Blacklists loaded: " + num_loaded + " lists, " + num_domains + " domains, " + num_ips + " IPs");
|
||||
mNumDomainRules = num_domains;
|
||||
mNumIPRules = num_ips;
|
||||
mUpdateInProgress = false;
|
||||
|
||||
@ -24,7 +24,6 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.net.VpnService;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.preference.PreferenceManager;
|
||||
|
||||
@ -42,7 +42,6 @@ import android.os.Build;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.os.ParcelFileDescriptor;
|
||||
import android.util.Log;
|
||||
import android.util.Pair;
|
||||
import android.util.SparseArray;
|
||||
import android.widget.Toast;
|
||||
@ -242,7 +241,7 @@ public class CaptureService extends VpnService implements Runnable {
|
||||
// An Intent without extras is delivered in case of always on VPN
|
||||
// https://developer.android.com/guide/topics/connectivity/vpn#always-on
|
||||
mIsAlwaysOnVPN = (intent != null);
|
||||
Log.d(CaptureService.TAG, "Missing capture settings, using SharedPrefs");
|
||||
Log.i(CaptureService.TAG, "Missing capture settings, using SharedPrefs");
|
||||
} else {
|
||||
// Use the provided settings
|
||||
mSettings = settings;
|
||||
@ -476,7 +475,7 @@ public class CaptureService extends VpnService implements Runnable {
|
||||
if (Intent.ACTION_PACKAGE_ADDED.equals(intent.getAction())) {
|
||||
boolean newInstall = !intent.getBooleanExtra(Intent.EXTRA_REPLACING, false);
|
||||
String packageName = intent.getData().getSchemeSpecificPart();
|
||||
Log.d(TAG, "ACTION_PACKAGE_ADDED [new=" + newInstall + "]: " + packageName);
|
||||
Log.i(TAG, "ACTION_PACKAGE_ADDED [new=" + newInstall + "]: " + packageName);
|
||||
|
||||
if(newInstall && Prefs.blockNewApps(mPrefs)) {
|
||||
Log.i(TAG, "Blocking newly installed app: " + packageName);
|
||||
@ -685,7 +684,7 @@ public class CaptureService extends VpnService implements Runnable {
|
||||
// If the network goes offline we roll back to the fallback DNS server to
|
||||
// avoid possibly using a private IP DNS server not reachable anymore
|
||||
if(network.getNetworkHandle() == mMonitoredNetwork) {
|
||||
Log.d(TAG, "Main network " + network + " lost, using fallback DNS " + FALLBACK_DNS_SERVER);
|
||||
Log.i(TAG, "Main network " + network + " lost, using fallback DNS " + FALLBACK_DNS_SERVER);
|
||||
dns_server = FALLBACK_DNS_SERVER;
|
||||
mMonitoredNetwork = 0;
|
||||
unregisterNetworkCallbacks();
|
||||
@ -744,7 +743,7 @@ public class CaptureService extends VpnService implements Runnable {
|
||||
boolean strict_mode = (linkProperties.getPrivateDnsServerName() != null);
|
||||
boolean opportunistic_mode = !strict_mode && linkProperties.isPrivateDnsActive();
|
||||
|
||||
Log.d(TAG, "Private DNS: " + (strict_mode ? "strict" : (opportunistic_mode ? "opportunistic" : "off")));
|
||||
Log.i(TAG, "Private DNS: " + (strict_mode ? "strict" : (opportunistic_mode ? "opportunistic" : "off")));
|
||||
if(!mSettings.root_capture && mSettings.auto_block_private_dns) {
|
||||
mDnsEncrypted = strict_mode;
|
||||
|
||||
@ -1371,7 +1370,7 @@ public class CaptureService extends VpnService implements Runnable {
|
||||
if(!mBilling.isFirewallVisible())
|
||||
return;
|
||||
|
||||
Log.d(TAG, "reloading firewall blocklist");
|
||||
Log.i(TAG, "reloading firewall blocklist");
|
||||
reloadBlocklist(mBlocklist.toListDescriptor());
|
||||
}
|
||||
|
||||
@ -1379,7 +1378,7 @@ public class CaptureService extends VpnService implements Runnable {
|
||||
if((INSTANCE == null) || !INSTANCE.mMalwareDetectionEnabled)
|
||||
return;
|
||||
|
||||
Log.d(TAG, "reloading malware whitelist");
|
||||
Log.i(TAG, "reloading malware whitelist");
|
||||
reloadMalwareWhitelist(INSTANCE.mWhitelist.toListDescriptor());
|
||||
}
|
||||
|
||||
@ -1422,6 +1421,8 @@ public class CaptureService extends VpnService implements Runnable {
|
||||
Log.d(TAG, "waitForCaptureStop done " + Thread.currentThread().getName());
|
||||
}
|
||||
|
||||
public static native int initLogger(String path, int level);
|
||||
public static native int writeLog(int logger, int lvl, String message);
|
||||
private static native void runPacketLoop(int fd, CaptureService vpn, int sdk);
|
||||
private static native void stopPacketLoop();
|
||||
private static native int getFdSetSize();
|
||||
|
||||
@ -20,7 +20,6 @@
|
||||
package com.emanuelef.remote_capture;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
import android.util.SparseArray;
|
||||
import android.util.SparseIntArray;
|
||||
|
||||
@ -393,7 +392,7 @@ public class ConnectionsRegister {
|
||||
}
|
||||
|
||||
public synchronized void releasePayloadMemory() {
|
||||
Log.d(TAG, "releaseFullPayloadMemory called");
|
||||
Log.i(TAG, "releaseFullPayloadMemory called");
|
||||
|
||||
for(int i=0; i<mCurItems; i++) {
|
||||
ConnectionDescriptor conn = mItemsRing[i];
|
||||
|
||||
@ -21,7 +21,6 @@ package com.emanuelef.remote_capture;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
|
||||
@ -19,8 +19,6 @@
|
||||
|
||||
package com.emanuelef.remote_capture;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import com.emanuelef.remote_capture.model.PayloadChunk;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
@ -326,4 +324,4 @@ public class HTTPReassembly {
|
||||
|
||||
return chunks.get(0).withPayload(reassembly);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
63
app/src/main/java/com/emanuelef/remote_capture/Log.java
Normal file
63
app/src/main/java/com/emanuelef/remote_capture/Log.java
Normal file
@ -0,0 +1,63 @@
|
||||
/*
|
||||
* This file is part of PCAPdroid.
|
||||
*
|
||||
* PCAPdroid is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* PCAPdroid is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with PCAPdroid. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Copyright 2020-22 - Emanuele Faranda
|
||||
*/
|
||||
|
||||
package com.emanuelef.remote_capture;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
public class Log {
|
||||
public static final int LOG_LEVEL_INFO = 4;
|
||||
public static int DEFAULT_LOGGER;
|
||||
public static int MITMADDON_LOGGER;
|
||||
|
||||
public static void init(String basedir) {
|
||||
DEFAULT_LOGGER = CaptureService.initLogger(basedir + "/pcapdroid.log", LOG_LEVEL_INFO);
|
||||
MITMADDON_LOGGER = CaptureService.initLogger(basedir + "/mitmaddon.log", LOG_LEVEL_INFO);
|
||||
android.util.Log.e("tag", basedir);
|
||||
}
|
||||
|
||||
public static void writeLog(int logger, int level, @Nullable String tag, @NonNull String message) {
|
||||
CaptureService.writeLog(logger, level, "[" + tag + "] " + message);
|
||||
}
|
||||
|
||||
public static void d(@Nullable String tag, @NonNull String message) {
|
||||
android.util.Log.d(tag, message);
|
||||
}
|
||||
|
||||
public static void i(@Nullable String tag, @NonNull String message) {
|
||||
android.util.Log.i(tag, message);
|
||||
writeLog(DEFAULT_LOGGER, android.util.Log.INFO, tag, message);
|
||||
}
|
||||
|
||||
public static void w(@Nullable String tag, @NonNull String message) {
|
||||
android.util.Log.w(tag, message);
|
||||
writeLog(DEFAULT_LOGGER, android.util.Log.WARN, tag, message);
|
||||
}
|
||||
|
||||
public static void e(@Nullable String tag, @NonNull String message) {
|
||||
android.util.Log.e(tag, message);
|
||||
writeLog(DEFAULT_LOGGER, android.util.Log.ERROR, tag, message);
|
||||
}
|
||||
|
||||
public static void wtf(@Nullable String tag, @NonNull String message) {
|
||||
android.util.Log.wtf(tag, message);
|
||||
writeLog(DEFAULT_LOGGER, android.util.Log.ASSERT, tag, message); // ANDROID_LOG_FATAL
|
||||
}
|
||||
}
|
||||
@ -35,7 +35,6 @@ import android.os.Message;
|
||||
import android.os.Messenger;
|
||||
import android.os.ParcelFileDescriptor;
|
||||
import android.os.RemoteException;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.core.content.pm.PackageInfoCompat;
|
||||
@ -69,7 +68,7 @@ public class MitmAddon {
|
||||
private final ServiceConnection mConnection = new ServiceConnection() {
|
||||
@Override
|
||||
public void onServiceConnected(ComponentName className, IBinder service) {
|
||||
Log.d(TAG, "Service connected");
|
||||
Log.i(TAG, "Service connected");
|
||||
mService = new Messenger(service);
|
||||
|
||||
if(mStopRequested)
|
||||
@ -80,7 +79,7 @@ public class MitmAddon {
|
||||
|
||||
@Override
|
||||
public void onServiceDisconnected(ComponentName className) {
|
||||
Log.d(TAG, "Service disconnected");
|
||||
Log.i(TAG, "Service disconnected");
|
||||
disconnect(); // call unbind to prevent new connections
|
||||
mReceiver.onMitmServiceDisconnect();
|
||||
}
|
||||
@ -211,7 +210,7 @@ public class MitmAddon {
|
||||
// This must be always called after connect, e.g. in the OnDestroy
|
||||
public void disconnect() {
|
||||
if(mService != null) {
|
||||
Log.d(TAG, "Unbinding service...");
|
||||
Log.i(TAG, "Unbinding service...");
|
||||
mContext.unbindService(mConnection);
|
||||
mService = null;
|
||||
}
|
||||
@ -278,12 +277,12 @@ public class MitmAddon {
|
||||
|
||||
public boolean stopProxy() {
|
||||
if(mService == null) {
|
||||
Log.d(TAG, "Not connected, postponing stop message");
|
||||
Log.i(TAG, "Not connected, postponing stop message");
|
||||
mStopRequested = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
Log.d(TAG, "Send stop message");
|
||||
Log.i(TAG, "Send stop message");
|
||||
Message msg = Message.obtain(null, MitmAPI.MSG_STOP_MITM);
|
||||
try {
|
||||
mService.send(msg);
|
||||
|
||||
@ -23,7 +23,6 @@ import android.content.Context;
|
||||
import android.net.Uri;
|
||||
import android.os.ParcelFileDescriptor;
|
||||
import android.os.SystemClock;
|
||||
import android.util.Log;
|
||||
import android.util.LruCache;
|
||||
import android.util.SparseArray;
|
||||
|
||||
@ -179,12 +178,12 @@ public class MitmReceiver implements Runnable, ConnectionsListener, MitmListener
|
||||
@Override
|
||||
public void run() {
|
||||
if(mSocketFd == null) {
|
||||
Log.d(TAG, "Null socket, abort");
|
||||
Log.e(TAG, "Null socket, abort");
|
||||
proxyRunning.postValue(false);
|
||||
return;
|
||||
}
|
||||
|
||||
Log.d(TAG, "Receiving data...");
|
||||
Log.i(TAG, "Receiving data...");
|
||||
try(DataInputStream istream = new DataInputStream(new ParcelFileDescriptor.AutoCloseInputStream(mSocketFd))) {
|
||||
while(mAddon.isConnected()) {
|
||||
String msg_type;
|
||||
@ -236,7 +235,7 @@ public class MitmReceiver implements Runnable, ConnectionsListener, MitmListener
|
||||
if(type == MsgType.MASTER_SECRET)
|
||||
logMasterSecret(msg);
|
||||
else if(type == MsgType.RUNNING) {
|
||||
Log.d(TAG, "MITM proxy is running");
|
||||
Log.i(TAG, "MITM proxy is running");
|
||||
proxyRunning.postValue(true);
|
||||
} else {
|
||||
ConnectionDescriptor conn = getConnByLocalPort(port);
|
||||
@ -258,7 +257,7 @@ public class MitmReceiver implements Runnable, ConnectionsListener, MitmListener
|
||||
}
|
||||
|
||||
proxyRunning.postValue(false);
|
||||
Log.d(TAG, "End receiving data");
|
||||
Log.i(TAG, "End receiving data");
|
||||
}
|
||||
|
||||
private boolean isSent(MsgType type) {
|
||||
|
||||
@ -22,7 +22,6 @@ package com.emanuelef.remote_capture;
|
||||
import android.app.Application;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.preference.PreferenceManager;
|
||||
@ -59,8 +58,9 @@ public class PCAPdroid extends Application {
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
|
||||
Log.init(getCacheDir().getAbsolutePath());
|
||||
Utils.BuildType buildtp = Utils.getVerifiedBuild(this);
|
||||
Log.d(TAG, "Build type: " + buildtp);
|
||||
Log.i(TAG, "Build type: " + buildtp);
|
||||
|
||||
CaocConfig.Builder builder = CaocConfig.Builder.create();
|
||||
if((buildtp == Utils.BuildType.PLAYSTORE) || (buildtp == Utils.BuildType.UNKNOWN)) {
|
||||
@ -123,4 +123,4 @@ public class PCAPdroid extends Application {
|
||||
mCtrlPermissions = new CtrlPermissions(this);
|
||||
return mCtrlPermissions;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -65,7 +65,6 @@ import android.text.SpannedString;
|
||||
import android.text.TextUtils;
|
||||
import android.text.method.LinkMovementMethod;
|
||||
import android.text.style.StyleSpan;
|
||||
import android.util.Log;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
@ -27,7 +27,6 @@ import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.Window;
|
||||
import android.view.WindowInsets;
|
||||
@ -48,6 +47,7 @@ import com.emanuelef.remote_capture.Billing;
|
||||
import com.emanuelef.remote_capture.BuildConfig;
|
||||
import com.emanuelef.remote_capture.CaptureHelper;
|
||||
import com.emanuelef.remote_capture.CaptureService;
|
||||
import com.emanuelef.remote_capture.Log;
|
||||
import com.emanuelef.remote_capture.PCAPdroid;
|
||||
import com.emanuelef.remote_capture.R;
|
||||
import com.emanuelef.remote_capture.Utils;
|
||||
|
||||
@ -29,10 +29,10 @@ import android.annotation.SuppressLint;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.util.Log;
|
||||
|
||||
import com.emanuelef.remote_capture.CaptureService;
|
||||
import com.emanuelef.remote_capture.ConnectionsRegister;
|
||||
import com.emanuelef.remote_capture.Log;
|
||||
import com.emanuelef.remote_capture.R;
|
||||
import com.emanuelef.remote_capture.fragments.ConnectionOverview;
|
||||
import com.emanuelef.remote_capture.fragments.ConnectionPayload;
|
||||
|
||||
@ -20,7 +20,6 @@
|
||||
package com.emanuelef.remote_capture.activities;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.Fragment;
|
||||
@ -28,6 +27,7 @@ import androidx.fragment.app.FragmentActivity;
|
||||
import androidx.viewpager2.adapter.FragmentStateAdapter;
|
||||
import androidx.viewpager2.widget.ViewPager2;
|
||||
|
||||
import com.emanuelef.remote_capture.Log;
|
||||
import com.emanuelef.remote_capture.R;
|
||||
import com.emanuelef.remote_capture.fragments.EditListFragment;
|
||||
import com.emanuelef.remote_capture.fragments.FirewallStatus;
|
||||
|
||||
@ -52,7 +52,6 @@ import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.provider.DocumentsContract;
|
||||
import android.provider.OpenableColumns;
|
||||
import android.util.Log;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
@ -63,6 +62,7 @@ import com.emanuelef.remote_capture.AppsResolver;
|
||||
import com.emanuelef.remote_capture.Billing;
|
||||
import com.emanuelef.remote_capture.BuildConfig;
|
||||
import com.emanuelef.remote_capture.CaptureHelper;
|
||||
import com.emanuelef.remote_capture.Log;
|
||||
import com.emanuelef.remote_capture.MitmReceiver;
|
||||
import com.emanuelef.remote_capture.fragments.ConnectionsFragment;
|
||||
import com.emanuelef.remote_capture.fragments.StatusFragment;
|
||||
|
||||
@ -20,7 +20,6 @@
|
||||
package com.emanuelef.remote_capture.activities;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.Fragment;
|
||||
@ -28,6 +27,7 @@ import androidx.fragment.app.FragmentActivity;
|
||||
import androidx.viewpager2.adapter.FragmentStateAdapter;
|
||||
import androidx.viewpager2.widget.ViewPager2;
|
||||
|
||||
import com.emanuelef.remote_capture.Log;
|
||||
import com.emanuelef.remote_capture.R;
|
||||
import com.emanuelef.remote_capture.fragments.EditListFragment;
|
||||
import com.emanuelef.remote_capture.fragments.BlacklistsFragment;
|
||||
|
||||
@ -24,7 +24,6 @@ import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.text.method.LinkMovementMethod;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.Log;
|
||||
import android.util.TypedValue;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
@ -41,6 +40,7 @@ import androidx.fragment.app.Fragment;
|
||||
import androidx.preference.PreferenceManager;
|
||||
|
||||
import com.emanuelef.remote_capture.Billing;
|
||||
import com.emanuelef.remote_capture.Log;
|
||||
import com.emanuelef.remote_capture.R;
|
||||
import com.emanuelef.remote_capture.Utils;
|
||||
import com.emanuelef.remote_capture.model.Prefs;
|
||||
@ -210,4 +210,4 @@ public class OnBoardingActivity extends AppIntro {
|
||||
startActivity(intent);
|
||||
finish();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -26,7 +26,6 @@ import android.net.InetAddresses;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.text.InputType;
|
||||
import android.util.Log;
|
||||
import android.util.Patterns;
|
||||
|
||||
import androidx.activity.result.ActivityResultLauncher;
|
||||
@ -44,6 +43,7 @@ import androidx.preference.PreferenceManager;
|
||||
import androidx.preference.SwitchPreference;
|
||||
|
||||
import com.emanuelef.remote_capture.Billing;
|
||||
import com.emanuelef.remote_capture.Log;
|
||||
import com.emanuelef.remote_capture.PCAPdroid;
|
||||
import com.emanuelef.remote_capture.Utils;
|
||||
import com.emanuelef.remote_capture.MitmAddon;
|
||||
|
||||
@ -22,13 +22,13 @@ package com.emanuelef.remote_capture.activities;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.MenuItem;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.preference.PreferenceManager;
|
||||
|
||||
import com.emanuelef.remote_capture.Log;
|
||||
import com.emanuelef.remote_capture.R;
|
||||
import com.emanuelef.remote_capture.fragments.AppsToggles;
|
||||
import com.emanuelef.remote_capture.model.AppDescriptor;
|
||||
|
||||
@ -21,7 +21,6 @@ package com.emanuelef.remote_capture.adapters;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
@ -33,6 +32,7 @@ import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.widget.SwitchCompat;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.emanuelef.remote_capture.Log;
|
||||
import com.emanuelef.remote_capture.R;
|
||||
import com.emanuelef.remote_capture.model.AppDescriptor;
|
||||
|
||||
|
||||
@ -22,7 +22,6 @@ package com.emanuelef.remote_capture.adapters;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.util.Log;
|
||||
import android.util.SparseIntArray;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
@ -35,6 +34,7 @@ import androidx.core.content.ContextCompat;
|
||||
import androidx.preference.PreferenceManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.emanuelef.remote_capture.Log;
|
||||
import com.emanuelef.remote_capture.PCAPdroid;
|
||||
import com.emanuelef.remote_capture.interfaces.ConnectionsListener;
|
||||
import com.emanuelef.remote_capture.model.AppDescriptor;
|
||||
|
||||
@ -21,7 +21,6 @@ package com.emanuelef.remote_capture.adapters;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
@ -34,6 +33,7 @@ import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.emanuelef.remote_capture.CaptureService;
|
||||
import com.emanuelef.remote_capture.HTTPReassembly;
|
||||
import com.emanuelef.remote_capture.Log;
|
||||
import com.emanuelef.remote_capture.R;
|
||||
import com.emanuelef.remote_capture.Utils;
|
||||
import com.emanuelef.remote_capture.model.ConnectionDescriptor;
|
||||
|
||||
@ -23,7 +23,6 @@ import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.util.Log;
|
||||
import android.view.ContextMenu;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MenuInflater;
|
||||
@ -38,6 +37,7 @@ import androidx.fragment.app.Fragment;
|
||||
|
||||
import com.emanuelef.remote_capture.CaptureService;
|
||||
import com.emanuelef.remote_capture.ConnectionsRegister;
|
||||
import com.emanuelef.remote_capture.Log;
|
||||
import com.emanuelef.remote_capture.PCAPdroid;
|
||||
import com.emanuelef.remote_capture.R;
|
||||
import com.emanuelef.remote_capture.activities.AppDetailsActivity;
|
||||
|
||||
@ -20,7 +20,6 @@
|
||||
package com.emanuelef.remote_capture.fragments;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
@ -38,6 +37,7 @@ import androidx.fragment.app.Fragment;
|
||||
import androidx.lifecycle.Lifecycle;
|
||||
|
||||
import com.emanuelef.remote_capture.AppsLoader;
|
||||
import com.emanuelef.remote_capture.Log;
|
||||
import com.emanuelef.remote_capture.R;
|
||||
import com.emanuelef.remote_capture.Utils;
|
||||
import com.emanuelef.remote_capture.adapters.AppsTogglesAdapter;
|
||||
|
||||
@ -22,7 +22,6 @@ package com.emanuelef.remote_capture.fragments;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
@ -38,6 +37,7 @@ import androidx.fragment.app.Fragment;
|
||||
import androidx.lifecycle.Lifecycle;
|
||||
|
||||
import com.emanuelef.remote_capture.CaptureService;
|
||||
import com.emanuelef.remote_capture.Log;
|
||||
import com.emanuelef.remote_capture.PCAPdroid;
|
||||
import com.emanuelef.remote_capture.R;
|
||||
import com.emanuelef.remote_capture.adapters.BlacklistsAdapter;
|
||||
|
||||
@ -22,7 +22,6 @@ package com.emanuelef.remote_capture.fragments;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
@ -41,6 +40,7 @@ import androidx.preference.PreferenceManager;
|
||||
|
||||
import com.emanuelef.remote_capture.CaptureService;
|
||||
import com.emanuelef.remote_capture.ConnectionsRegister;
|
||||
import com.emanuelef.remote_capture.Log;
|
||||
import com.emanuelef.remote_capture.R;
|
||||
import com.emanuelef.remote_capture.Utils;
|
||||
import com.emanuelef.remote_capture.activities.ConnectionDetailsActivity;
|
||||
|
||||
@ -28,7 +28,6 @@ import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.util.Log;
|
||||
import android.view.ContextMenu;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
@ -55,6 +54,7 @@ import com.emanuelef.remote_capture.AppsResolver;
|
||||
import com.emanuelef.remote_capture.Billing;
|
||||
import com.emanuelef.remote_capture.CaptureService;
|
||||
import com.emanuelef.remote_capture.ConnectionsRegister;
|
||||
import com.emanuelef.remote_capture.Log;
|
||||
import com.emanuelef.remote_capture.PCAPdroid;
|
||||
import com.emanuelef.remote_capture.R;
|
||||
import com.emanuelef.remote_capture.Utils;
|
||||
|
||||
@ -23,7 +23,6 @@ import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.ActionMode;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
@ -47,6 +46,7 @@ import androidx.fragment.app.Fragment;
|
||||
import androidx.lifecycle.Lifecycle;
|
||||
|
||||
import com.emanuelef.remote_capture.CaptureService;
|
||||
import com.emanuelef.remote_capture.Log;
|
||||
import com.emanuelef.remote_capture.R;
|
||||
import com.emanuelef.remote_capture.Utils;
|
||||
import com.emanuelef.remote_capture.adapters.ListEditAdapter;
|
||||
|
||||
@ -26,7 +26,6 @@ import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
@ -47,6 +46,7 @@ import androidx.preference.PreferenceManager;
|
||||
|
||||
import com.emanuelef.remote_capture.CaptureService;
|
||||
import com.emanuelef.remote_capture.ConnectionsRegister;
|
||||
import com.emanuelef.remote_capture.Log;
|
||||
import com.emanuelef.remote_capture.PCAPdroid;
|
||||
import com.emanuelef.remote_capture.R;
|
||||
import com.emanuelef.remote_capture.Utils;
|
||||
|
||||
@ -22,7 +22,6 @@ import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
@ -31,6 +30,7 @@ import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceFragmentCompat;
|
||||
|
||||
import com.emanuelef.remote_capture.Geolocation;
|
||||
import com.emanuelef.remote_capture.Log;
|
||||
import com.emanuelef.remote_capture.R;
|
||||
import com.emanuelef.remote_capture.Utils;
|
||||
|
||||
|
||||
@ -28,7 +28,6 @@ import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.text.method.LinkMovementMethod;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
@ -49,6 +48,7 @@ import androidx.preference.PreferenceManager;
|
||||
|
||||
import com.emanuelef.remote_capture.AppsLoader;
|
||||
import com.emanuelef.remote_capture.AppsResolver;
|
||||
import com.emanuelef.remote_capture.Log;
|
||||
import com.emanuelef.remote_capture.MitmReceiver;
|
||||
import com.emanuelef.remote_capture.interfaces.AppsLoadListener;
|
||||
import com.emanuelef.remote_capture.model.AppDescriptor;
|
||||
|
||||
@ -27,7 +27,6 @@ import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.security.KeyChain;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.Toast;
|
||||
|
||||
@ -38,6 +37,7 @@ import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
|
||||
import com.emanuelef.remote_capture.Log;
|
||||
import com.emanuelef.remote_capture.R;
|
||||
import com.emanuelef.remote_capture.Utils;
|
||||
import com.emanuelef.remote_capture.interfaces.MitmListener;
|
||||
|
||||
@ -3,9 +3,9 @@ package com.emanuelef.remote_capture.model;
|
||||
import android.content.Context;
|
||||
import android.os.SystemClock;
|
||||
import android.util.ArrayMap;
|
||||
import android.util.Log;
|
||||
|
||||
import com.emanuelef.remote_capture.CaptureService;
|
||||
import com.emanuelef.remote_capture.Log;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
@ -19,8 +19,6 @@
|
||||
|
||||
package com.emanuelef.remote_capture.model;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class ConnectionUpdate {
|
||||
|
||||
@ -24,13 +24,13 @@ import android.content.SharedPreferences;
|
||||
import android.graphics.Typeface;
|
||||
import android.text.style.StyleSpan;
|
||||
import android.util.ArrayMap;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.collection.ArraySet;
|
||||
import androidx.preference.PreferenceManager;
|
||||
|
||||
import com.emanuelef.remote_capture.AppsResolver;
|
||||
import com.emanuelef.remote_capture.Log;
|
||||
import com.emanuelef.remote_capture.R;
|
||||
import com.emanuelef.remote_capture.Utils;
|
||||
import com.google.gson.Gson;
|
||||
|
||||
@ -2,9 +2,9 @@ package com.emanuelef.remote_capture.pcap_dump;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
import android.util.Log;
|
||||
|
||||
import com.emanuelef.remote_capture.CaptureService;
|
||||
import com.emanuelef.remote_capture.Log;
|
||||
import com.emanuelef.remote_capture.Utils;
|
||||
import com.emanuelef.remote_capture.interfaces.PcapDumper;
|
||||
|
||||
|
||||
@ -20,9 +20,9 @@
|
||||
package com.emanuelef.remote_capture.pcap_dump;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import com.emanuelef.remote_capture.CaptureService;
|
||||
import com.emanuelef.remote_capture.Log;
|
||||
import com.emanuelef.remote_capture.Utils;
|
||||
import com.emanuelef.remote_capture.interfaces.PcapDumper;
|
||||
|
||||
|
||||
@ -9,6 +9,7 @@ add_library(capture SHARED
|
||||
crc32.c
|
||||
blacklist.c
|
||||
pcap_utils.c
|
||||
log_writer.c
|
||||
jni_impl.c)
|
||||
|
||||
# nDPI
|
||||
|
||||
@ -57,7 +57,7 @@ static void kill_pcapd(pcapdroid_t *nc) {
|
||||
pid = atoi(pid_s);
|
||||
|
||||
if(pid != 0) {
|
||||
log_d("Killing old pcapd with pid %d", pid);
|
||||
log_i("Killing old pcapd with pid %d", pid);
|
||||
run_shell_cmd("kill", pid_s, true, false);
|
||||
}
|
||||
|
||||
@ -185,7 +185,7 @@ static int connectPcapd(pcapdroid_t *pd) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
log_d("Connected to pcapd");
|
||||
log_i("Connected to pcapd");
|
||||
|
||||
cleanup:
|
||||
unlink(PCAPD_SOCKET_PATH);
|
||||
@ -518,7 +518,7 @@ int run_root(pcapdroid_t *pd) {
|
||||
pd_refresh_time(pd);
|
||||
next_purge_ms = pd->now_ms + PERIODIC_PURGE_TIMEOUT_MS;
|
||||
|
||||
log_d("Starting packet loop");
|
||||
log_i("Starting packet loop");
|
||||
|
||||
while(running) {
|
||||
pcapd_hdr_t hdr;
|
||||
|
||||
@ -33,7 +33,7 @@ static int resolve_uid(pcapdroid_t *pd, const zdtun_5tuple_t *conn_info) {
|
||||
char appbuf[64];
|
||||
|
||||
get_appname_by_uid(pd, uid, appbuf, sizeof(appbuf));
|
||||
log_i( "%s [%d/%s]", buf, uid, appbuf);
|
||||
log_d( "%s [%d/%s]", buf, uid, appbuf);
|
||||
} else {
|
||||
uid = UID_UNKNOWN;
|
||||
log_w("%s => UID not found!", buf);
|
||||
@ -154,7 +154,7 @@ static bool check_dns_req_allowed(pcapdroid_t *pd, zdtun_conn_t *conn, pkt_conte
|
||||
ip.ip4 = pd->vpn.ipv4.dns_server;
|
||||
zdtun_set_dnat_info(pd->zdt, &ip, htons(53), 4);
|
||||
|
||||
log_d("Using new DNS server");
|
||||
log_i("Using new DNS server");
|
||||
}
|
||||
|
||||
if(pctx->tuple->ipproto == IPPROTO_ICMP)
|
||||
@ -209,7 +209,7 @@ static bool check_dns_req_allowed(pcapdroid_t *pd, zdtun_conn_t *conn, pkt_conte
|
||||
}
|
||||
|
||||
if(block_private_dns) {
|
||||
log_i("blocking packet directed to the DNS server");
|
||||
log_d("blocking packet directed to the DNS server");
|
||||
return(false);
|
||||
}
|
||||
|
||||
@ -370,7 +370,7 @@ void vpn_process_ndpi(pcapdroid_t *pd, const zdtun_5tuple_t *tuple, pd_conn_t *d
|
||||
if(block_private_dns && !data->to_block &&
|
||||
(data->l7proto == NDPI_PROTOCOL_TLS) &&
|
||||
data->info && blacklist_match_domain(pd->vpn.known_dns_servers, data->info)) {
|
||||
log_i("blocking connection to private DNS server");
|
||||
log_d("blocking connection to private DNS server");
|
||||
data->blacklisted_internal = true;
|
||||
data->to_block = true;
|
||||
}
|
||||
@ -474,7 +474,7 @@ int run_vpn(pcapdroid_t *pd) {
|
||||
pd_refresh_time(pd);
|
||||
next_purge_ms = pd->now_ms + PERIODIC_PURGE_TIMEOUT_MS;
|
||||
|
||||
log_d("Starting packet loop [tunfd=%d]", pd->vpn.tunfd);
|
||||
log_i("Starting packet loop");
|
||||
|
||||
while(running) {
|
||||
int max_fd;
|
||||
|
||||
@ -19,15 +19,18 @@
|
||||
|
||||
#if ANDROID
|
||||
|
||||
#include <pthread.h>
|
||||
#include "pcapdroid.h"
|
||||
#include "pcap_utils.h"
|
||||
#include "common/utils.h"
|
||||
#include "log_writer.h"
|
||||
|
||||
// This files contains functions to make the capture core communicate
|
||||
// with the Android system.
|
||||
// Exported functions are defined in pcapdroid.h
|
||||
|
||||
static pcapdroid_t *global_pd = NULL;
|
||||
static pthread_t jni_thread;
|
||||
|
||||
jni_classes_t cls;
|
||||
jni_methods_t mids;
|
||||
@ -37,9 +40,19 @@ jni_enum_t enums;
|
||||
/* ******************************************************* */
|
||||
|
||||
static void log_callback(int lvl, const char *line) {
|
||||
if(lvl >= ANDROID_LOG_FATAL) {
|
||||
pcapdroid_t *pd = global_pd;
|
||||
pcapdroid_t *pd = global_pd;
|
||||
|
||||
// quick path for debug logs
|
||||
if(lvl < PD_DEFAULT_LOGGER_LEVEL)
|
||||
return;
|
||||
|
||||
pd_log_write(PD_DEFAULT_LOGGER, lvl, line);
|
||||
|
||||
// ensure that we are invoking jni from the attached thread
|
||||
if(!pd || !(pthread_equal(jni_thread, pthread_self())))
|
||||
return;
|
||||
|
||||
if(lvl >= ANDROID_LOG_FATAL) {
|
||||
// This is a fatal error, report it to the gui
|
||||
jobject info_string = (*pd->env)->NewStringUTF(pd->env, line);
|
||||
|
||||
@ -607,6 +620,7 @@ Java_com_emanuelef_remote_1capture_CaptureService_runPacketLoop(JNIEnv *env, jcl
|
||||
pd.filesdir_len = strlen(pd.filesdir);
|
||||
|
||||
global_pd = &pd;
|
||||
jni_thread = pthread_self();
|
||||
logcallback = log_callback;
|
||||
signal(SIGPIPE, SIG_IGN);
|
||||
|
||||
@ -641,7 +655,7 @@ Java_com_emanuelef_remote_1capture_CaptureService_runPacketLoop(JNIEnv *env, jcl
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_emanuelef_remote_1capture_CaptureService_stopPacketLoop(JNIEnv *env, jclass type) {
|
||||
/* NOTE: the select on the packets loop uses a timeout to wake up periodically */
|
||||
log_i( "stopPacketLoop called");
|
||||
log_i("stopPacketLoop called");
|
||||
running = false;
|
||||
}
|
||||
|
||||
@ -846,6 +860,28 @@ Java_com_emanuelef_remote_1capture_CaptureService_setPayloadMode(JNIEnv *env, jc
|
||||
|
||||
/* ******************************************************* */
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_com_emanuelef_remote_1capture_CaptureService_initLogger(JNIEnv *env, jclass clazz,
|
||||
jstring path, jint level) {
|
||||
const char *path_s = (*env)->GetStringUTFChars(env, path, 0);
|
||||
int rv = pd_init_logger(path_s, level);
|
||||
(*env)->ReleaseStringUTFChars(env, path, path_s);
|
||||
return rv;
|
||||
}
|
||||
|
||||
/* ******************************************************* */
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_com_emanuelef_remote_1capture_CaptureService_writeLog(JNIEnv *env, jclass clazz,
|
||||
jint logger, jint lvl, jstring message) {
|
||||
const char *message_s = (*env)->GetStringUTFChars(env, message, 0);
|
||||
int rv = pd_log_write(logger, lvl, message_s);
|
||||
(*env)->ReleaseStringUTFChars(env, message, message_s);
|
||||
return rv;
|
||||
}
|
||||
|
||||
/* ******************************************************* */
|
||||
|
||||
char* getStringPref(pcapdroid_t *pd, const char *key, char *buf, int bufsize) {
|
||||
JNIEnv *env = pd->env;
|
||||
|
||||
|
||||
111
app/src/main/jni/core/log_writer.c
Normal file
111
app/src/main/jni/core/log_writer.c
Normal file
@ -0,0 +1,111 @@
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include "log_writer.h"
|
||||
|
||||
struct log_writer;
|
||||
|
||||
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
static struct log_writer **loggers = NULL;
|
||||
static int num_loggers = 0;
|
||||
|
||||
struct log_writer {
|
||||
FILE *f;
|
||||
int id;
|
||||
int level;
|
||||
};
|
||||
|
||||
static void pd_destroy_logger(struct log_writer *logger) {
|
||||
fclose(logger->f);
|
||||
pd_free(logger);
|
||||
}
|
||||
|
||||
void pd_close_loggers() {
|
||||
pthread_mutex_lock(&mutex);
|
||||
|
||||
for(int i=0; i<num_loggers; i++)
|
||||
pd_destroy_logger(loggers[i]);
|
||||
pd_free(loggers);
|
||||
loggers = NULL;
|
||||
num_loggers = 0;
|
||||
|
||||
pthread_mutex_unlock(&mutex);
|
||||
}
|
||||
|
||||
int pd_init_logger(const char *path, int min_lvl) {
|
||||
FILE *f = fopen(path, "w");
|
||||
int rv;
|
||||
|
||||
if(!f) {
|
||||
#ifdef ANDROID
|
||||
__android_log_print(ANDROID_LOG_ERROR, logtag,
|
||||
"pd_init_logger %s failed[%d]: %s", path, errno, strerror(errno));
|
||||
#endif
|
||||
return -errno;
|
||||
}
|
||||
|
||||
struct log_writer *logger = (struct log_writer*) pd_calloc(1, sizeof(struct log_writer));
|
||||
if(!logger) {
|
||||
rv = -errno;
|
||||
fclose(f);
|
||||
return rv;
|
||||
}
|
||||
|
||||
logger->level = min_lvl;
|
||||
logger->f = f;
|
||||
|
||||
pthread_mutex_lock(&mutex);
|
||||
loggers = pd_realloc(loggers, sizeof(void*) * (num_loggers + 1));
|
||||
if(!loggers) {
|
||||
pd_destroy_logger(logger);
|
||||
rv = -1;
|
||||
} else {
|
||||
loggers[num_loggers++] = logger;
|
||||
logger->id = rv = num_loggers;
|
||||
}
|
||||
pthread_mutex_unlock(&mutex);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
int pd_log_write(int logger_id, int lvl, const char *msg) {
|
||||
int rv = 0;
|
||||
char dtbuf[64];
|
||||
struct tm tm;
|
||||
time_t tnow = time(NULL);
|
||||
|
||||
strftime(dtbuf, sizeof(dtbuf), "%d/%b/%Y %H:%M:%S", localtime_r(&tnow, &tm));
|
||||
|
||||
pthread_mutex_lock(&mutex);
|
||||
|
||||
if((logger_id < 0) || (logger_id >= num_loggers)) {
|
||||
rv = -ENOENT;
|
||||
goto unlock;
|
||||
}
|
||||
|
||||
struct log_writer *logger = loggers[logger_id];
|
||||
|
||||
if(logger->level > lvl)
|
||||
goto unlock;
|
||||
|
||||
if(ferror(logger->f)) {
|
||||
rv = -EINVAL;
|
||||
goto unlock;
|
||||
}
|
||||
|
||||
fprintf(logger->f, "[%c] %s - %s\n", loglvl2char(lvl), dtbuf, msg);
|
||||
if(ferror(logger->f)) {
|
||||
#ifdef ANDROID
|
||||
__android_log_print(ANDROID_LOG_ERROR, logtag,
|
||||
"pd_log %d failed[%d]: %s", logger_id, errno, strerror(errno));
|
||||
#endif
|
||||
rv = -errno;
|
||||
goto unlock;
|
||||
}
|
||||
|
||||
fflush(logger->f);
|
||||
|
||||
unlock:
|
||||
pthread_mutex_unlock(&mutex);
|
||||
return rv;
|
||||
}
|
||||
13
app/src/main/jni/core/log_writer.h
Normal file
13
app/src/main/jni/core/log_writer.h
Normal file
@ -0,0 +1,13 @@
|
||||
#ifndef PCAPDROID_LOG_WRITER_H
|
||||
#define PCAPDROID_LOG_WRITER_H
|
||||
|
||||
#include "common/utils.h"
|
||||
|
||||
#define PD_DEFAULT_LOGGER 0
|
||||
#define PD_DEFAULT_LOGGER_LEVEL ANDROID_LOG_INFO
|
||||
|
||||
int pd_init_logger(const char *path, int min_lvl);
|
||||
int pd_log_write(int logger, int lvl, const char *msg);
|
||||
void pd_close_loggers();
|
||||
|
||||
#endif //PCAPDROID_LOG_WRITER_H
|
||||
@ -1100,7 +1100,7 @@ void pd_dump_packet(pcapdroid_t *pd, const char *pktbuf, int pktlen, const struc
|
||||
JAVA_PCAP_BUFFER_SIZE, pd->pcap_dump.buffer_idx, rec_size);
|
||||
else if((pd->pcap_dump.max_dump_size > 0) &&
|
||||
((pd->pcap_dump.tot_size + rec_size) >= pd->pcap_dump.max_dump_size)) {
|
||||
log_d("Max dump size reached, stop the dump");
|
||||
log_i("Max dump size reached, stop the dump");
|
||||
stop_pcap_dump(pd);
|
||||
} else {
|
||||
pcap_dump_rec(pd, (u_char *) pd->pcap_dump.buffer + pd->pcap_dump.buffer_idx,
|
||||
@ -1198,7 +1198,7 @@ int pd_run(pcapdroid_t *pd) {
|
||||
// Run the capture
|
||||
int rv = pd->root_capture ? run_root(pd) : run_vpn(pd);
|
||||
|
||||
log_d("Stopped packet loop");
|
||||
log_i("Stopped packet loop");
|
||||
|
||||
// send last dump
|
||||
if(pd->cb.send_stats_dump)
|
||||
@ -1216,7 +1216,7 @@ int pd_run(pcapdroid_t *pd) {
|
||||
|
||||
if(pd->malware_detection.enabled) {
|
||||
if(pd->malware_detection.reload_in_progress) {
|
||||
log_d("Joining blacklists reload_worker");
|
||||
log_i("Joining blacklists reload_worker");
|
||||
pthread_join(pd->malware_detection.reload_worker, NULL);
|
||||
}
|
||||
if(pd->malware_detection.bl)
|
||||
@ -1245,8 +1245,8 @@ int pd_run(pcapdroid_t *pd) {
|
||||
pd_free(e);
|
||||
}
|
||||
|
||||
log_d("Host LRU cache size: %d", ip_lru_size(pd->ip_to_host));
|
||||
log_d("Discarded fragments: %ld", pd->num_discarded_fragments);
|
||||
log_i("Host LRU cache size: %d", ip_lru_size(pd->ip_to_host));
|
||||
log_i("Discarded fragments: %ld", pd->num_discarded_fragments);
|
||||
ip_lru_destroy(pd->ip_to_host);
|
||||
|
||||
return(rv);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user