Apktool 2.3.3-dirty : Error During APK Recompilation - apktool

What I Am Trying To Do?
I am trying to decompile a apk file , modify it and recompile it again.
What is my working Environment?
root#l0calh0st:~/Desktop/APKS/Projects# uname -a
Linux l0calh0st 4.15.0-kali3-amd64 #1 SMP Debian 4.15.17-1kali1 (2018-04-25) x86_64 GNU/Linux
What I Have Done?
apt-get update
apt-get full-upgrade
apt-get install apktool
Reference to [https://ibotpeaches.github.io/Apktool/documentation/] I decompile a apk using apktool d RAR_v5.60.build56.apk command and i succeed.
But without even modifying the file when i tried to recompile it using apktool b RAR_v5.60.build56 command i got something like this:
I: Using Apktool 2.3.3-dirty
I: Checking whether sources has changed...
I: Smaling smali folder into classes.dex...
I: Checking whether resources has changed...
I: Building resources...
W: aapt: brut.common.BrutException: brut.common.BrutException: Could not extract resource: /prebuilt/aapt/linux/aapt (defaulting to $PATH binary)
W: A/ ( 2465): First type is not attr!
brut.androlib.AndrolibException: brut.common.BrutException: could not exec (exit code = 134): [aapt, p, --min-sdk-version, 17, --target-sdk-version, 27, --version-code, 56, --version-name, 5.60.build56, --no-version-vectors, -F, /tmp/APKTOOL6407896023935370654.tmp, -0, arsc, -0, res/drawable-hdpi-v4/abc_ab_share_pack_mtrl_alpha.9.png, -0, png, -0, res/drawable-hdpi-v4/abc_btn_switch_to_on_mtrl_00001.9.png, -0, res/drawable-hdpi-v4/abc_btn_switch_to_on_mtrl_00012.9.png, -0, res/drawable-hdpi-v4/abc_cab_background_top_mtrl_alpha.9.png, -0, res/drawable-hdpi-v4/abc_list_divider_mtrl_alpha.9.png, -0, res/drawable-hdpi-v4/abc_list_focused_holo.9.png, -0, res/drawable-hdpi-v4/abc_list_longpressed_holo.9.png, -0, res/drawable-hdpi-v4/abc_list_pressed_holo_dark.9.png, -0, res/drawable-hdpi-v4/abc_list_pressed_holo_light.9.png, -0, res/drawable-hdpi-v4/abc_list_selector_disabled_holo_dark.9.png, -0, res/drawable-hdpi-v4/abc_list_selector_disabled_holo_light.9.png, -0, res/drawable-hdpi-v4/abc_menu_hardkey_panel_mtrl_mult.9.png, -0, res/drawable-hdpi-v4/abc_popup_background_mtrl_mult.9.png, -0, res/drawable-hdpi-v4/abc_scrubber_primary_mtrl_alpha.9.png, -0, res/drawable-hdpi-v4/abc_scrubber_track_mtrl_alpha.9.png, -0, res/drawable-hdpi-v4/abc_spinner_mtrl_am_alpha.9.png, -0, res/drawable-hdpi-v4/abc_switch_track_mtrl_alpha.9.png, -0, res/drawable-hdpi-v4/abc_tab_indicator_mtrl_alpha.9.png, -0, res/drawable-hdpi-v4/abc_textfield_activated_mtrl_alpha.9.png, -0, res/drawable-hdpi-v4/abc_textfield_default_mtrl_alpha.9.png, -0, res/drawable-hdpi-v4/abc_textfield_search_activated_mtrl_alpha.9.png, -0, res/drawable-hdpi-v4/abc_textfield_search_default_mtrl_alpha.9.png, -0, res/drawable-hdpi-v4/notification_bg_low_normal.9.png, -0, res/drawable-hdpi-v4/notification_bg_low_pressed.9.png, -0, res/drawable-hdpi-v4/notification_bg_normal.9.png, -0, res/drawable-hdpi-v4/notification_bg_normal_pressed.9.png, -0, res/drawable-ldrtl-hdpi-v17/abc_spinner_mtrl_am_alpha.9.png, -0, res/drawable-ldrtl-mdpi-v17/abc_spinner_mtrl_am_alpha.9.png, -0, res/drawable-ldrtl-xhdpi-v17/abc_spinner_mtrl_am_alpha.9.png, -0, res/drawable-ldrtl-xxhdpi-v17/abc_spinner_mtrl_am_alpha.9.png, -0, res/drawable-ldrtl-xxxhdpi-v17/abc_spinner_mtrl_am_alpha.9.png, -0, res/drawable-mdpi-v4/abc_ab_share_pack_mtrl_alpha.9.png, -0, res/drawable-mdpi-v4/abc_btn_switch_to_on_mtrl_00001.9.png, -0, res/drawable-mdpi-v4/abc_btn_switch_to_on_mtrl_00012.9.png, -0, res/drawable-mdpi-v4/abc_cab_background_top_mtrl_alpha.9.png, -0, res/drawable-mdpi-v4/abc_list_divider_mtrl_alpha.9.png, -0, res/drawable-mdpi-v4/abc_list_focused_holo.9.png, -0, res/drawable-mdpi-v4/abc_list_longpressed_holo.9.png, -0, res/drawable-mdpi-v4/abc_list_pressed_holo_dark.9.png, -0, res/drawable-mdpi-v4/abc_list_pressed_holo_light.9.png, -0, res/drawable-mdpi-v4/abc_list_selector_disabled_holo_dark.9.png, -0, res/drawable-mdpi-v4/abc_list_selector_disabled_holo_light.9.png, -0, res/drawable-mdpi-v4/abc_menu_hardkey_panel_mtrl_mult.9.png, -0, res/drawable-mdpi-v4/abc_popup_background_mtrl_mult.9.png, -0, res/drawable-mdpi-v4/abc_scrubber_primary_mtrl_alpha.9.png, -0, res/drawable-mdpi-v4/abc_scrubber_track_mtrl_alpha.9.png, -0, res/drawable-mdpi-v4/abc_spinner_mtrl_am_alpha.9.png, -0, res/drawable-mdpi-v4/abc_switch_track_mtrl_alpha.9.png, -0, res/drawable-mdpi-v4/abc_tab_indicator_mtrl_alpha.9.png, -0, res/drawable-mdpi-v4/abc_textfield_activated_mtrl_alpha.9.png, -0, res/drawable-mdpi-v4/abc_textfield_default_mtrl_alpha.9.png, -0, res/drawable-mdpi-v4/abc_textfield_search_activated_mtrl_alpha.9.png, -0, res/drawable-mdpi-v4/abc_textfield_search_default_mtrl_alpha.9.png, -0, res/drawable-mdpi-v4/notification_bg_low_normal.9.png, -0, res/drawable-mdpi-v4/notification_bg_low_pressed.9.png, -0, res/drawable-mdpi-v4/notification_bg_normal.9.png, -0, res/drawable-mdpi-v4/notification_bg_normal_pressed.9.png, -0, res/drawable-xhdpi-v4/abc_ab_share_pack_mtrl_alpha.9.png, -0, res/drawable-xhdpi-v4/abc_btn_switch_to_on_mtrl_00001.9.png, -0, res/drawable-xhdpi-v4/abc_btn_switch_to_on_mtrl_00012.9.png, -0, res/drawable-xhdpi-v4/abc_cab_background_top_mtrl_alpha.9.png, -0, res/drawable-xhdpi-v4/abc_list_divider_mtrl_alpha.9.png, -0, res/drawable-xhdpi-v4/abc_list_focused_holo.9.png, -0, res/drawable-xhdpi-v4/abc_list_longpressed_holo.9.png, -0, res/drawable-xhdpi-v4/abc_list_pressed_holo_dark.9.png, -0, res/drawable-xhdpi-v4/abc_list_pressed_holo_light.9.png, -0, res/drawable-xhdpi-v4/abc_list_selector_disabled_holo_dark.9.png, -0, res/drawable-xhdpi-v4/abc_list_selector_disabled_holo_light.9.png, -0, res/drawable-xhdpi-v4/abc_menu_hardkey_panel_mtrl_mult.9.png, -0, res/drawable-xhdpi-v4/abc_popup_background_mtrl_mult.9.png, -0, res/drawable-xhdpi-v4/abc_scrubber_primary_mtrl_alpha.9.png, -0, res/drawable-xhdpi-v4/abc_scrubber_track_mtrl_alpha.9.png, -0, res/drawable-xhdpi-v4/abc_spinner_mtrl_am_alpha.9.png, -0, res/drawable-xhdpi-v4/abc_switch_track_mtrl_alpha.9.png, -0, res/drawable-xhdpi-v4/abc_tab_indicator_mtrl_alpha.9.png, -0, res/drawable-xhdpi-v4/abc_textfield_activated_mtrl_alpha.9.png, -0, res/drawable-xhdpi-v4/abc_textfield_default_mtrl_alpha.9.png, -0, res/drawable-xhdpi-v4/abc_textfield_search_activated_mtrl_alpha.9.png, -0, res/drawable-xhdpi-v4/abc_textfield_search_default_mtrl_alpha.9.png, -0, res/drawable-xhdpi-v4/notification_bg_low_normal.9.png, -0, res/drawable-xhdpi-v4/notification_bg_low_pressed.9.png, -0, res/drawable-xhdpi-v4/notification_bg_normal.9.png, -0, res/drawable-xhdpi-v4/notification_bg_normal_pressed.9.png, -0, res/drawable-xxhdpi-v4/abc_ab_share_pack_mtrl_alpha.9.png, -0, res/drawable-xxhdpi-v4/abc_btn_switch_to_on_mtrl_00001.9.png, -0, res/drawable-xxhdpi-v4/abc_btn_switch_to_on_mtrl_00012.9.png, -0, res/drawable-xxhdpi-v4/abc_cab_background_top_mtrl_alpha.9.png, -0, res/drawable-xxhdpi-v4/abc_list_divider_mtrl_alpha.9.png, -0, res/drawable-xxhdpi-v4/abc_list_focused_holo.9.png, -0, res/drawable-xxhdpi-v4/abc_list_longpressed_holo.9.png, -0, res/drawable-xxhdpi-v4/abc_list_pressed_holo_dark.9.png, -0, res/drawable-xxhdpi-v4/abc_list_pressed_holo_light.9.png, -0, res/drawable-xxhdpi-v4/abc_list_selector_disabled_holo_dark.9.png, -0, res/drawable-xxhdpi-v4/abc_list_selector_disabled_holo_light.9.png, -0, res/drawable-xxhdpi-v4/abc_menu_hardkey_panel_mtrl_mult.9.png, -0, res/drawable-xxhdpi-v4/abc_popup_background_mtrl_mult.9.png, -0, res/drawable-xxhdpi-v4/abc_scrubber_primary_mtrl_alpha.9.png, -0, res/drawable-xxhdpi-v4/abc_scrubber_track_mtrl_alpha.9.png, -0, res/drawable-xxhdpi-v4/abc_spinner_mtrl_am_alpha.9.png, -0, res/drawable-xxhdpi-v4/abc_switch_track_mtrl_alpha.9.png, -0, res/drawable-xxhdpi-v4/abc_tab_indicator_mtrl_alpha.9.png, -0, res/drawable-xxhdpi-v4/abc_textfield_activated_mtrl_alpha.9.png, -0, res/drawable-xxhdpi-v4/abc_textfield_default_mtrl_alpha.9.png, -0, res/drawable-xxhdpi-v4/abc_textfield_search_activated_mtrl_alpha.9.png, -0, res/drawable-xxhdpi-v4/abc_textfield_search_default_mtrl_alpha.9.png, -0, res/drawable-xxxhdpi-v4/abc_btn_switch_to_on_mtrl_00001.9.png, -0, res/drawable-xxxhdpi-v4/abc_btn_switch_to_on_mtrl_00012.9.png, -0, res/drawable-xxxhdpi-v4/abc_spinner_mtrl_am_alpha.9.png, -0, res/drawable-xxxhdpi-v4/abc_switch_track_mtrl_alpha.9.png, -0, res/drawable-xxxhdpi-v4/abc_tab_indicator_mtrl_alpha.9.png, -0, arsc, -I, /root/.local/share/apktool/framework/1.apk, -S, /root/Desktop/APKS/Projects/RAR_v5.60.build56/res, -M, /root/Desktop/APKS/Projects/RAR_v5.60.build56/AndroidManifest.xml]
What is wrong? I need a solution. Please help. Thanks.

Try clearing framework dir:
$ apktool empty-framework-dir
Solved problem for me

I resolved this problem by uninstalling Apktool 2.3.3-dirty and installing Apktool 2.3.3 from official website. Also I replaced openjdk-10 by jdk-1.8. Sorry for being so stupid.

we can use --use-aapt2 flag.
apktool_2.5.0.jar b --use-aapt2 -f -d -p apt_folder -o app.apk

This error is due to some files are missing after the recompilation, so it is showing we cant rebuild the apk, files required to compile the apk :
these are the required files to build apk with apktool b command. Files after decompiling the apk :
You can see in both the images, 2 files are missing after the recompilation I don't know why but you can still edit the decompiled files and again drag the missing two files
The files are available in the github repo(AndroRAT) check once you will get the idea.

Related

Adding Current Values to future Dates SQL

I'm trying to load data for future dates. My scenario is something like this, I have data for 2016, 2017 and 2018(until August). Each year has Current and 'Prior Year Same Day' values associated. Data is aggregated to Month. Requirement is that I load data for future dates as well, that is for September 2018 through August 2019 using 'PYSD' values. For example, the 'Current' value for September 2017 will be 'PYSD' value for September 2018 and so on. When I try this particular logic I get an error stating 'overflow' and I'm unable to figure out what's causing. This happens only with the second condition in my WHERE clause. My SELECT clause aggregates a months' data and outputs as '08-01-2018' - there will be one row per month/year.
SELECT
CAST(YEAR(DATEADD(dd, 364, CalendarDate)) AS VARCHAR(250))
+ '-' + RIGHT('00' + CAST(MONTH(DATEADD(dd, 364, CalendarDate)) AS VARCHAR(250)), 2)
+ '-' + '01' AS MonthPeriod
FROM
DateTable
WHERE
DATEADD(DD, 364, CalendarDate) > '08-31-2018'
AND DATEADD(DD, 364, CalendarDate) < '08-01-2019'
My error:
Msg 517, Level 16, State 3, Line 1
Adding a value to a 'date' column caused an overflow.
Also, open to suggestions if there is a simpler way. I'm on SQL Server.
TIA.
Added sample data:
As you stated in one of the answers to the original question, your max date is 9999-12-31
This means that any sort of DATEADD(DD, 364, CalendarDate) should always fail. Doesn't matter if you are trying to check against a date in 2018, because it has to do the dateadd first, and that gets an overflow.
To avoid that overflow do your date add the other way - compare the actual CalendarDate to one year before your target date.
CalendarDate > DATEADD(DD, -364, '08-31-2018')
or just
CalendarDate > '2017-08-31'
I'll leave the rest of how you should specify the date, or whether it should be 364,365,first of month etc to the rest of the discussion.
What is the maximum date in your DateTable ? You probably have dates that is with year 9999. So adding 364 will cause it to overflow. It has nothing to do with the SELECT clause
On your query, you can simply do this
SELECT DATEADD(MONTH,
DATEDIFF(MONTH, 0,
DATEADD(DAY, 364, CalendarDate)), 0) AS MonthPeriod
Note :
DATEADD(MONTH, DATEDIFF(MONTH, 0, <date>), 0) will gives you the 1st day of the month
EDIT :
The overflow error is because the DateTable contains rows with date 9999. Adding 364 days to it will cause over flow.
One quick way to resolve is to delete those rows where year is 9998 or 9999
Another way is to change your query such that it does not add days to the CalendarDate
WHERE CalendarDate > DATEADD(DAY, 364, '2018-08-31')
AND CalendarDate < DATEADD(DAY, 364, '2019-08-01')
Note : i uses date string in ISO format YYYY-MM-DD. It is recommended to specify date in such format as it is unambiguous.
And the complete query will be
SELECT DATEADD(MONTH,
DATEDIFF(MONTH, 0,
DATEADD(DAY, 364, CalendarDate)), 0) AS MonthPeriod
FROM DateTable
WHERE CalendarDate > DATEADD(DAY, 364, '2018-08-31')
AND CalendarDate < DATEADD(DAY, 364, '2019-08-01')

sql server or Tsql - Datediff and Dateadd functions

select datediff(mm, 0, getdate())
This function returns the output as 1376. I dont understand on how this has been calculated
select dateadd(mm, datediff(mm, 0, getdate()), -1)
This function returns the output as "2014-08-31 00:00:00.000" which is Aug-31st.
My understanding according to dateadd() - mm stands for month.
select dateadd(mm, datediff(mm, 0, getdate()), -2)
The output is "2014-08-30 00:00:00.000".
Which is again confusing for me as this was supposed to negate the month by -1. But instead, it is doing it by day difference.
mm is month, but you should use "month". It is then obvious what you are doing.
The statement:
select datediff(month, 0, getdate())
is getting the number of months since date is 0. SQL Server stores dates as the number of days since Jan 1, 1900. So, this base date is 1,376 months in the past (as I write this).
When you write:
select dateadd(month, datediff(month, 0, getdate()), -1)
Then you are adding the number of months since 1900-01-01 to the date with the value -1. The -1 is interpreted as a datetime, which corresponds to 1899-12-31. Hence, when you add the months you are getting the last day of the previous month. When you change -1 to -2, you get the second to last day, because you are counting from 1899-12-30.

SQL Ce- Query to return previous month does not work

I used a query that somebody here on SO provided me with to get the results from the before currentdate, which works perfectly:
WHERE IssuedOn >= DATEDIFF(D, 1, GETDATE()) and IssuedOn < DATEDIFF(D, 0, GETDATE()) ";
I though that for the previous month, changing D for M will be enough but obviously I am missing something:
WHERE IssuedOn >= DATEDIFF(M, 1, GETDATE()) and IssuedOn < DATEDIFF(M, 0, GETDATE()) ";
This does not work. I need to return rows where IssuedOn is from previous month from current date.
The short answer:
The following SQL will get the values for your date range:
-- The beginning of the current month
DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE()), 0)
-- The beginning of the previous month
DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE())-1, 0)
-- The beginning of the next month
DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE())+1, 0)
You can replace MONTH with any other datepart value to get date ranges for things like years, hours, days, etc...
The long answer:
The reason your days query worked but your months query did not is that SQL Server stores DATETIME objects as FLOATs. The integer portion representing the date as days since 1900-01-01 00:00:00.000 (hereafter referred to as "0"). The decimal portion representing the time (as a percentage of 24 hours).
If you call DATEDIFF(DAY, 0, GETDATE()), it will get the number of days since "0", which basically is the same as converting the FLOAT representation of GETDATE() to an INTEGER representation (truncating the minutes and leaving you at 00:00). For instance, if I run SELECT CAST(GETDATE() AS FLOAT) today, I get "41675.3452306327". If I run SELECT DATEDIFF(DAY, 0, GETDATE()), I get "41675".
If you call DATEDIFF(MONTH, 0, GETDATE()), you will get the number of months since "0". Today, this gives me "1369". If you try to compare that value to a DATETIME, it will simply convert "1369" to a DATETIME, treating it as "1369 days since 0" and result in a DATETIME of "1903-10-02 00:00:00.000". To see this for yourself, try: SELECT CAST(DATEDIFF(MONTH, 0, GETDATE()) AS DATETIME).
If you want to trim the days (and time-stamp) out of a DATETIME, you need to take the results of your DATEDIFF query and add it back to "0" with the DATEDIFF function, like so:
DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE()), 0)
This basically takes date (to the month) and figures out how many months have passed since "0", then adds that number of months to "0". In short, it returns a DATETIME that represents the beginning of the current month.
If you want to get the previous or next month, you can simply decrement or increment the value returned by the DATEDIFF function before passing it into the call to DATEADD, like so:
DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE())+1, 0) -- Get the next month

TSQl: Select Current Date - 6 Days and set time to 12:01 AM

I am trying to get current date - 6 days. That is easy.
Now I am trying to get current date - 6 days + 12:01 AM.
So if today is 3-2-2012 11:14 AM.
I want to get 2-25-2012 12:01 AM
These 2 selects will give me current date - 6, but will not reset the time to 12:01 AM
select getdate()-6
SELECT DATEADD(day, -6, CURRENT_TIMESTAMP);
SELECT DATEADD(minute, 1, DATEADD(DAY, DATEDIFF(DAY, 0, GETDATE()) - 6, 0))
is equivalent to
SELECT DATEADD(minute, 1, DATEADD(DAY, DATEDIFF(DAY, '19000101', GETDATE()) - 6, '19000101'))
I think you will find this option faster and more flexible than the varchar implementations. by keeping the data types as they are, you don't have to worry about the vagaries of the cast/convert results.
See Louis Davidson for one of the full explainations:
http://sqlblog.com/blogs/louis_davidson/archive/2011/02/09/some-date-math-fun.aspx
Using the following will give you the result in a datetime format:
SELECT CAST(Convert(varchar(10), DateAdd(d, -6, getdate()), 101)
+ ' 12:01 AM' as datetime)
Result: 2012-02-25 00:01:00.000
Once you have the datetime that you want, you can convert it to many different formats.
Or you can do the following which is in a varchar format:
select Convert(varchar(10), DateAdd(d, -6, getdate()), 110) + ' 12:01 AM'
which results in 02-25-2012 12:01 AM
One less conversion that #Phil Helmer's solution:
SELECT DATEADD(DAY, DATEDIFF(DAY, '19000101', GETDATE()), '1899-12-26T12:01:00')
Since some people are apparently unaware that everything "to the right" of the element specified in that DATEADD/DATEDIFF pair is effectively taken from the right-hand constant. Everything "to the left" (and including the actual element) can be used to achieve offsetting effects.
(The above left/right are assuming that the entire datetime value is being interpreted with year to the left and milliseconds to the right, with all intermediate values in "size" order)
Edited - I've also updated my answer to subsume the -6 into the right-hand value. Its possible to create all kinds of offsetting by picking suitable values for the two constants.
The relationship between the two datetime constants specified in the expression ought to be expressed, at least in a comment alongside the usage. In the above, I'm using 1/1/1900 as a base point, and computing the number of midnight transitions between then and now (as DATEDIFF always works). I'm then adding that number of days onto the point in time 6 days earlier (e.g. 26/12/1899) at exactly 00:01 in the morning...
SELECT DATEADD(dd, -6, DATEDIFF(dd, 0, GETDATE())) + '12:01'

First day Of this week and last week

I am currently getting first day Of this week and last week values with vbscript function in 2/12/2009 format. I was wondering if it was possible with SQL query.
These statements should do what you want in TSQL. Note, the statements are based on the current date. You can replace getdate() for whatever date you wish:
Select dateadd(wk, datediff(wk, 0, getdate()) - 1, 0) as LastWeekStart
Select dateadd(wk, datediff(wk, 0, getdate()), 0) as ThisWeekStart
Select dateadd(wk, datediff(wk, 0, getdate()) + 1, 0) as NextWeekStart
There are lots of other date routines here.
Ben's answer gives the wrong answer if today is Sunday. Regardless of whether the first day of the week is Sunday or Monday, the current date should be included in the current week. When I run his code for 3/24/2013, it gives me a ThisWeekStart of 3/25/2013. I used the following code instead:
SELECT DATEADD(DAY, 1 - DATEPART(DW, '3/24/2013'), '3/24/2013')
Get the first day of current week.
for extra information use this link.
http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_dayofweek
select date(curdate()-DAYOFWEEK(curdate()-1)) as dat;