How can I build an apk from 'apktool d -s -o' folder - build

I run apktool d -s -o foldername first to decode an apk file.So the classes.dex remained in the folder.Then I replace the classes.dex file and wanna package a new apkfile.So I run apktool b foldername on the terminal.But errors came up:
I: Using Apktool 2.0.3
I: Checking whether resources has changed...
I: Building resources...
res/drawable/$ic_launcher_foreground__0.xml: Invalid file name: must contain only [a-zA-Z0-9_.]
A/ ( 6108): First type is not attr!
Exception in thread "main" brut.androlib.AndrolibException: brut.androlib.AndrolibException: brut.common.BrutException: could not exec command: [/var/folders/1x/rbs7f_y145qf3f9dbbzktwlw0000gn/T/brut_util_Jar_7766331736141549579.tmp, p, --forced-package-id, 127, --min-sdk-version, 27, --target-sdk-version, 27, --version-code, 1, --version-name, 1.0, -F, /var/folders/1x/rbs7f_y145qf3f9dbbzktwlw0000gn/T/APKTOOL1668967197700881167.tmp, -0, arsc, -0, version, -0, arsc, -I, /Users/eilir/Library/apktool/framework/1.apk, -S, /Users/eilir/work6/安卓/new3/res, -M, /Users/eilir/work6/安卓/new3/AndroidManifest.xml]
at brut.androlib.Androlib.buildResourcesFull(Androlib.java:472)
at brut.androlib.Androlib.buildResources(Androlib.java:410)
at brut.androlib.Androlib.build(Androlib.java:298)
at brut.androlib.Androlib.build(Androlib.java:268)
at brut.apktool.Main.cmdBuild(Main.java:225)
at brut.apktool.Main.main(Main.java:84)
Caused by: brut.androlib.AndrolibException: brut.common.BrutException: could not exec command: [/var/folders/1x/rbs7f_y145qf3f9dbbzktwlw0000gn/T/brut_util_Jar_7766331736141549579.tmp, p, --forced-package-id, 127, --min-sdk-version, 27, --target-sdk-version, 27, --version-code, 1, --version-name, 1.0, -F, /var/folders/1x/rbs7f_y145qf3f9dbbzktwlw0000gn/T/APKTOOL1668967197700881167.tmp, -0, arsc, -0, version, -0, arsc, -I, /Users/eilir/Library/apktool/framework/1.apk, -S, /Users/eilir/work6/安卓/new3/res, -M, /Users/eilir/work6/安卓/new3/AndroidManifest.xml]
at brut.androlib.res.AndrolibResources.aaptPackage(AndrolibResources.java:425)
at brut.androlib.Androlib.buildResourcesFull(Androlib.java:458)
... 5 more
Caused by: brut.common.BrutException: could not exec command: [/var/folders/1x/rbs7f_y145qf3f9dbbzktwlw0000gn/T/brut_util_Jar_7766331736141549579.tmp, p, --forced-package-id, 127, --min-sdk-version, 27, --target-sdk-version, 27, --version-code, 1, --version-name, 1.0, -F, /var/folders/1x/rbs7f_y145qf3f9dbbzktwlw0000gn/T/APKTOOL1668967197700881167.tmp, -0, arsc, -0, version, -0, arsc, -I, /Users/eilir/Library/apktool/framework/1.apk, -S, /Users/eilir/work6/安卓/new3/res, -M, /Users/eilir/work6/安卓/new3/AndroidManifest.xml]
at brut.util.OS.exec(OS.java:89)
at brut.androlib.res.AndrolibResources.aaptPackage(AndrolibResources.java:419)
... 6 more
I supposed that's because the classes.dex file remaining in the folder.How should I do?

I just wanna replace the classes.dex file in the apk.If in Windows ,that's easy to do with RAR software , but no way on MacOS.

Related

Why does '$' for funcname in git log -L cause an infinite search?

You can search for a filename and function name in git log with git log -L :funcname:filename.
I ran into an issue where we had been running this search programmatically and the funcname was set to '$', which caused an endless search. (e.g. git log -L :$:somefile.py)
'$' means end of string in regex, but why does this cause an endless search loop when other regex characters like '^' or '?' don't? What unique effects does the '$' character have?
I was able to reproduce this locally and step through the code using gdb.
This looks like a bug in the find_funcname_match_regexp function. It eventually ends up matching $ against the empty string, which matches successfully but causes no changes in the pointers used to mark the position in the file, resulting in an infinite loop.
Here's a walk through of the reproducer. In this example, we're running git log against the file main.go which has the following content:
package main
import "fmt"
func main() {
fmt.Println("example repository for demonstrating git log bug")
}
Start gdb and set a breakpoint at the beginning of the while loop in line-range.c. Arrange to print the value of start after each break:
(gdb) break line-range.c:140
Breakpoint 1 at 0x5a7a89: file line-range.c, line 140.
(gdb) commands
Type commands for breakpoint(s) 1, one per line.
End with a line saying just "end".
>p start
>end
(gdb)
Run git log -L :$:main.go under the control of gdb:
(gdb) run log -L :$:main.go
Starting program: /home/lars/src/git/git log -L :$:main.go
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
[Detaching after fork from child process 2469232]
Breakpoint 1, find_funcname_matching_regexp (xecfg=0x0, start=0x8477c0 "package main\n\nimport \"fmt\"\n\nfunc main() {\n\tfmt.Println(\"example repository for demonstrating git log bug\")\n}\n", regexp=0x7fffffffc020) at line-range.c:140
140 reg_error = regexec(regexp, start, 1, match, 0);
$1 = 0x8477c0 "package main\n\nimport \"fmt\"\n\nfunc main() {\n\tfmt.Println(\"example repository for demonstrating git log bug\")\n}\n"
In this output, we can see that start is pointing at the beginning of the file:
$1 = 0x8477c0 "package main\n\nimport \"fmt\"\n\nfunc main() {\n\tfmt.Println(\"example repository for demonstrating git log bug\")\n}\n"
Skip a few iterations:
(gdb) c 7
Will ignore next 6 crossings of breakpoint 1. Continuing.
Breakpoint 1, find_funcname_matching_regexp (xecfg=0x0, start=0x84782b "}\n", regexp=0x7fffffffc020) at line-range.c:140
140 reg_error = regexec(regexp, start, 1, match, 0);
$2 = 0x84782b "}\n"
Here we see that start now points at the last line in the file.
Watch what happens if we iterate a few more times:
(gdb) c
Continuing.
Breakpoint 1, find_funcname_matching_regexp (xecfg=0x0, start=0x84782d "", regexp=0x7fffffffc020) at line-range.c:140
140 reg_error = regexec(regexp, start, 1, match, 0);
$3 = 0x84782d ""
(gdb) c
Continuing.
Breakpoint 1, find_funcname_matching_regexp (xecfg=0x0, start=0x84782d "", regexp=0x7fffffffc020) at line-range.c:140
140 reg_error = regexec(regexp, start, 1, match, 0);
$4 = 0x84782d ""
(gdb) c
Continuing.
Breakpoint 1, find_funcname_matching_regexp (xecfg=0x0, start=0x84782d "", regexp=0x7fffffffc020) at line-range.c:140
140 reg_error = regexec(regexp, start, 1, match, 0);
$5 = 0x84782d ""
After one more iteration of the loop, start now points at the empty string. It keeps this value in every subsequent iteration, and we never break out of the while loop.
I've submitted a patch to git that should correct this behavior.
You can follow the discussion there to see if they like my patch or if they decide there is a more appropriate way to resolve the problem.
With the patched version of the code, we see the following behavior instead:
$ git log -L :$:main.go
fatal: -L parameter '$' starting at line 1: no match

How to get the Clover report displayed in Jenkins, when using pipelines?

I'm setting up a Jenkins project for a PHP project. I installed the Clover plugin and want to see Clover reports on my project's page. Following the Clover plugin pipeline documentation I added this snippet to my pipeline:
step([
$class:'CloverPublisher',
cloverReportDir: 'build/coverage',
cloverReportFileName: 'build/logs/clover.xml',
healthyTarget: [methodCoverage: 70, conditionalCoverage: 70, statementCoverage: 70],
unhealthyTarget: [methodCoverage: 50, conditionalCoverage: 50, statementCoverage: 50],
failingTarget: [methodCoverage: 0, conditionalCoverage: 0, statementCoverage: 0]
])
The relevant folder build/coverage and file build/logs/clover.xml exist:
$ cd /path/ma/project
$ ls build/coverage
ModuleA ModuleB ModuleC dashboard.html index.html
$ ls build/logs
clover.xml crap4j.xml junit.xml
But there is no Clover report displayed on the Jenkins project page. Instead of this only a new link OpenClover HTML Report is shown in the build's navigation. This link leads to the HTML coverage report.
What am I doing wrong? How to get the Clover report displayed?
Jenkinsfile
pipeline {
agent {
node {
label params.LABEL
customWorkspace params.PROJECT_ROOT
}
}
stages {
stage('Build') {
steps {
sh 'hostname'
sh 'pwd'
}
}
stage ('Test') {
steps {
sh 'echo "Test"'
// sh './vendor/bin/phpunit ./test/Unit'
sh 'vendor/bin/phpunit --testsuite "unit-app-only"'
step([
$class: 'XUnitBuilder',
tools: [
PHPUnit([
pattern: 'build/logs/junit.xml',
skipNoTestFiles: true,
failIfNotNew: false,
deleteOutputFiles: false,
stopProcessingIfError: true
])
]
])
step([
$class:'CloverPublisher',
cloverReportDir: 'build/coverage',
cloverReportFileName: 'build/logs/clover.xml',
healthyTarget: [methodCoverage: 70, conditionalCoverage: 70, statementCoverage: 70],
unhealthyTarget: [methodCoverage: 50, conditionalCoverage: 50, statementCoverage: 50],
failingTarget: [methodCoverage: 0, conditionalCoverage: 0, statementCoverage: 0]
])
publishHTML([
allowMissing: true,
alwaysLinkToLastBuild: false,
keepAll: true,
reportDir: 'build/coverage',
reportFiles: 'index.html',
reportName: 'HTML Publisher Report'
])
}
}
}
}
Check if you have installed the Clover plugin and if the path to the clover.xml is correct (for example in my case the path is '''/var/jenkins_home/workspace/Front-Test-Coverage/intellst-front/output/coverage/jest''')
Clover plugin

awslogs-agent-setup.py not working on Ubuntu 17.10 (artful)

This works fine on ubuntu 16.04, but not on 17.10
+ curl https://s3.amazonaws.com/aws-cloudwatch/downloads/latest/awslogs-agent-setup.py -O
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
^M 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0^M100 56093 100 56093 0 0 56093 0 0:00:01 --:--:-- 0:00:01 98929
+ chmod +x ./awslogs-agent-setup.py
+ ./awslogs-agent-setup.py -n -c /etc/awslogs/awslogs.conf -r us-west-2
Step 1 of 5: Installing pip ...^[[0mlibyaml-dev does not exist in system ^[[0m^[[92mDONE^[[0m
Step 2 of 5: Downloading the latest CloudWatch Logs agent bits ... ^[[0mTraceback (most recent call last):
File "./awslogs-agent-setup.py", line 1317, in <module>
main()
File "./awslogs-agent-setup.py", line 1313, in main
setup.setup_artifacts()
File "./awslogs-agent-setup.py", line 858, in setup_artifacts
self.install_awslogs_cli()
File "./awslogs-agent-setup.py", line 570, in install_awslogs_cli
subprocess.call([AWSCLI_CMD, 'configure', 'set', 'plugins.cwlogs', 'cwlogs'], env=DEFAULT_ENV)
File "/usr/lib/python2.7/subprocess.py", line 168, in call
return Popen(*popenargs, **kwargs).wait()
File "/usr/lib/python2.7/subprocess.py", line 390, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1025, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
I noticed that earlier on in the process, in the AWS boilerplate it failed to install libyaml-dev but not sure if that's the only problem.
Always find the answer right after I post it...
Here's my modified CF template command:
050_install_awslogs:
command: !Sub
"/bin/bash -x\n
exec >>/var/log/cf_050_install_awslogs.log 2>&1 \n
echo 050_install_awslogs...\n
set -xe\n
# Get the CloudWatch Logs agent\n
mkdir /opt/awslogs\n
cd /opt/awslogs\n
# Needed for python3 in 17.10\n
apt-get install -y libyaml-dev python-dev \n
pip3 install awscli-cwlogs\n
# avoid it complaining about not having /var/awslogs/bin/aws binary\n
if [ ! -d /var/awslogs/bin ] ; then\n
mkdir -p /var/awslogs/bin\n
ln -s /usr/local/bin/aws /var/awslogs/bin/aws\n
fi\n
curl https://s3.amazonaws.com/aws-cloudwatch/downloads/latest/awslogs-agent-setup.py -O\n
chmod +x ./awslogs-agent-setup.py\n
# Hack for python 3.6 & old awslogs-agent-setup.py\n
sed -i 's/3,6/3,7/' awslogs-agent-setup.py\n
./awslogs-agent-setup.py -n -c /etc/awslogs/awslogs.conf -r ${AWS::Region}\n
echo 050_install_awslogs end\n
"
Not entirely sure about the need for the dir creation but I expect this is a temporary case that will get resolved soon as one still needs to fudge the python 3.6 compatibility check.
it may be installable using python 2.7 as well, but that felt like going backwards at this point as the my rationale for 17.10 was python 3.6.
Credit for the yaml package and dir creation idea to https://forums.aws.amazon.com/thread.jspa?threadID=265977 but I prefer to avoid easy_install.
I had similar issue on Ubuntu 18.04.
Instruction from AWS for standalone install worked for my case.
To download and run it standalone, use the following commands and follow the prompts:
curl https://s3.amazonaws.com/aws-cloudwatch/downloads/latest/awslogs-agent-setup.py -O
curl https://s3.amazonaws.com/aws-cloudwatch/downloads/latest/AgentDependencies.tar.gz -O
tar xvf AgentDependencies.tar.gz -C /tmp/
sudo python ./awslogs-agent-setup.py --region us-east-1 --dependency-path /tmp/AgentDependencies

How can I run "echo $?" in clojure through clojure.java.shell?

I try to do it like:
(shell/sh "echo" '"$?")
However, it returns
{:exit 0, :out "$?\n", :err ""}
So how can I give $? as an argument but string to "echo" with clojure.java.shell?
When you execute a command in Bash, the return value of the program will be bound to $?. It means that when you execute echo "$?" in bash it will replace $? with the last return value and only then call the echo command. It is internal to bash (and bash-like shells) and not available in other programming language such as Java or Clojure.
Clojure's clojure.java.shell/sh basically calls Runtime.getRuntime().exec(...). The return value will be under the :exit key of the returned map.
An example to a successful sh call:
(clojure.java.shell/sh "ls" "target")
=>
{:exit 0, :out "classes\nrepl-port\nstale\n", :err ""}
An unsuccessfull call:
(clojure.java.shell/sh "ls" "nothing")
=>
{:exit 2, :out "", :err "ls: cannot access 'nothing': No such file or directory\n"}
IMHO it's not possible to get what you want with shell/sh.
When you run echo $? in the shell, the shell rewrites it into echo 0 (assuming that the last command is successful).
when you run shell/sh, it just invokes the **Runtime.exec(["echo" '"$?"]) in background. $? is passed to echo and echo has no idea what $ means.

Store intermediate values into array with Ruby inject

I want to store ruby inject values into array I found one good example (on site http://matthewcarriere.com/2008/06/23/using-select-reject-collect-inject-and-detect/) but its returning Fixnum instead of array.
[1,2,3,4].inject([]) {|acc,n| acc << n+n}
this is returning 262144. However I want array as [2, 4, 6, 8].
Any help is appreciated.
it works in my machine.
Have you tried it in a new irb session?
Which version of ruby are you using?
$ ruby --version
ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-linux]
$ irb --version
irb 0.9.6(09/06/30)
$ irb
irb(main):001:0> [1,2,3,4].inject([]) {|acc,n| acc << n+n}
=> [2, 4, 6, 8]
irb(main):002:0>