Skip to content

Instantly share code, notes, and snippets.

@packmad
packmad / getInputStreamFromApkResource.java
Last active December 21, 2015 11:21
Read a file from another APK programmatically under Android
public static InputStream getInputStreamFromApkResource(String apkFilePath, String apkResPath) throws IOException {
JarFile jarFile = new JarFile(apkFilePath);
JarEntry jarEntry = jarFile.getJarEntry(apkResPath);
return jarFile.getInputStream(jarEntry);
}
// Example usage reading the file "SecureManifest.xml" under "assets" folder:
File sdcard = Environment.getExternalStorageDirectory();
File apkFile = new File(sdcard, "file.apk");
@packmad
packmad / loadXMLFromString.java
Created December 28, 2015 15:20
transform a String into an org.w3c.dom.Document
import org.w3c.dom.Document;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.xml.sax.InputSource;
public static Document loadXMLFromString(String xml) {
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
try {
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
InputSource inputSource = new InputSource(new StringReader(xml));
LOG_NAME = datetime.datetime.now().strftime("%Y-%m-%d_%H-%M-%S.log")
@packmad
packmad / dockerOnlinerBash.sh
Last active February 23, 2024 10:44
Remove all docker images one liner
# enter in the bash of the first container
docker exec -it $(docker ps | head -n 2 | tail -n 1 | cut -d " " -f 1) bash
# delete all containers
docker ps -a | tail -n +2 | cut -d " " -f 1 | xargs docker rm
# delete all images
docker images | tail -n +2 | tr -s " " | cut -d " " -f 3 | xargs docker rmi -f
@packmad
packmad / printargv.c
Created November 8, 2016 17:52
Print argvector
#include <stdio.h>
int main (int argc, char *argv[])
{
int i;
for(i=0;i<argc;i++) {
printf("%d %s\n", i, argv[i]);
}
return 0;
}
@packmad
packmad / invoke.sh
Created November 9, 2016 14:50
Wrapper which ensures equal stack offsets
#!/bin/sh
while getopts "dte:h?" opt ; do
case "$opt" in
h|\?)
printf "usage: %s -e KEY=VALUE prog [args...]\n" $(basename $0)
exit 0
;;
t)
tty=1
@packmad
packmad / mund.py
Last active November 11, 2016 14:12
Calculate most used but not dangerous Android permissions
import itertools
# https://developer.android.com/guide/topics/security/permissions.html#normal-dangerous
group_dangerous = {
"CALENDAR": {"READ_CALENDAR", "WRITE_CALENDAR"},
"CAMERA": {"CAMERA"},
"CONTACTS": {"READ_CONTACTS", "WRITE_CONTACTS", "GET_ACCOUNTS"},
"LOCATION": {"ACCESS_FINE_LOCATION", "ACCESS_COARSE_LOCATION"},
"MICROPHONE": {"RECORD_AUDIO"},
"PHONE": {"READ_PHONE_STATE", "CALL_PHONE", "READ_CALL_LOG", "WRITE_CALL_LOG", "ADD_VOICEMAIL", "USE_SIP",
@packmad
packmad / file_processing.py
Created December 20, 2016 13:23
Read a file and filter its content into another file
with open("/tmp/output.txt", "w") as output_file:
with open("/tmp/input.txt", "r") as input_file:
for line in input_file:
# process line
print(line, file=output_file, end="")
sudo apt-get install software-properties-common
sudo add-apt-repository "deb http://ppa.launchpad.net/webupd8team/java/ubuntu xenial main"
sudo sh -c 'echo deb https://www.charlesproxy.com/packages/apt/ charles-proxy main > /etc/apt/sources.list.d/charles.list'
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 5F16B97C1AD28806
sudo apt-get update
@packmad
packmad / ExecuteExternalCommand.java
Created February 20, 2018 09:42
Correct way to create another process and execute an external command
static List<String> execute(final List<String> args) throws IOException, InterruptedException {
final List<String> output = new LinkedList<>();
ProcessBuilder pb = new ProcessBuilder(args);
pb.redirectErrorStream(true);
Process process = pb.start();
BufferedReader br = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line;
while ((line = br.readLine()) != null) {
output.add(line);
}