[REF][SUGGESTION] clean up your codes for OC/UV and old kernel codes if possible - Galaxy S II Original Android Development

hi all,
first of all, i would like to say that i'm no expert in c, and this post is not intended to blame anyone but want to raise this concern only.
since i started to mod i9000's kernel source code, i found some unneeded conditional statements in the original source and modded OC/UV sections which can be avoided very easily and thus consuming less resources.
let's take a look in this example from the original source:
Code:
for (i = 0; i < LOOP_CNT; i++) {
tmp = __raw_readb(iem_base + S5PV310_APC_DBG_DLYCODE);
sum_result += tmp;
hpm[i] = tmp;
}
for (i = 0; i < LOOP_CNT; i++)
printk(KERN_INFO "ASV : hpm[%d] = %d value\n", i, hpm[i]);
the second for loop is definitely unnecessary, and it should be changed to something like:
Code:
for (i = 0; i < LOOP_CNT; i++) {
tmp = __raw_readb(iem_base + S5PV310_APC_DBG_DLYCODE);
sum_result += tmp;
hpm[i] = tmp;
printk(KERN_INFO "ASV : hpm[%d] = %d value\n", i, hpm[i]);
}
let's take a look at another extreme case, taken from the OC/UV section:
Code:
if (index < L6)
{
if (old_index == L0)
index = L1;
if (old_index == L1)
index = L2;
if (old_index == L2)
index = L3;
if (old_index == L3)
index = L4;
if (old_index == L4)
index = L5;
if (old_index == L5)
index = L6;
}
it is obvious that, if old_index=L0, it has to go thru the remaining 5 if statements which shouldnt be. isnt it be nice and more efficient to chg it to something like below or use switch case instead?
Code:
if (index < L6)
{
if (old_index == L0)
index = L1;
else if (old_index == L1)
index = L2;
else if (old_index == L2)
index = L3;
else if (old_index == L3)
index = L4;
...
...
...
...
}
since we all aim at producing better and faster kernels, i think this is a good practice to clean up the codes while we r modding
thx for your kind attention

and this is the most ridiculous part that i've ever seen in my life, which can be found in I9000 source also. if u have 10 frequencies set, then instead of running the loop 10 times, this will run 50 times in total
arch/arm/mach-s5pv310/cpufreq.c, inside static int s5pv310_update_dvfs_table()
for (i = 1; i < CPUFREQ_LEVEL_END; i++) {
s5pv310_freq_table[i-1].index = s5pv310_lookup_freq_table.index - 1;
s5pv310_freq_table[i-1].frequency = s5pv310_lookup_freq_table.frequency;
printk(KERN_INFO "index = %d, frequency = %d\n",
s5pv310_freq_table[i-1].index, s5pv310_freq_table[i-1].frequency);
}
for (i = 1; i < CPUFREQ_LEVEL_END; i++) {
s5pv310_volt_table[i-1].index = s5pv310_lookup_volt_table.index - 1;
s5pv310_volt_table[i-1].arm_volt = s5pv310_lookup_volt_table.arm_volt;
printk(KERN_INFO "index = %d, arm_volt = %d\n",
s5pv310_volt_table[i-1].index, s5pv310_volt_table[i-1].arm_volt);
}
for (i = 1; i < CPUFREQ_LEVEL_END; i++) {
s5pv310_apll_pms_table[i-1] = s5pv310_lookup_apll_pms_table;
printk(KERN_INFO "apll pms_table = 0x%08x\n", s5pv310_apll_pms_table[i-1]);
}
for (i = 1; i < CPUFREQ_LEVEL_END; i++) {
for (j = 0; j < 7; j++) {
clkdiv_cpu0[i-1][j] = clkdiv_cpu0_lookup[j];
printk("%d, ", clkdiv_cpu0[i-1][j]);
}
printk("\n");
}
for (i = 1; i < CPUFREQ_LEVEL_END; i++) {
for (j = 0; j < 2; j++) {
clkdiv_cpu1[i-1][j] = clkdiv_cpu1_lookup[j];
printk("%d, ", clkdiv_cpu1[i-1][j]);
}
printk("\n");
}

Interesting...
Sent from my GT-I9100 using XDA Premium.

This might be right. My C is bad, but some OC/UV patches look really quite 'whatever works' for me. I dont say its bad - having something is better than nothing.
Its always good if some skilled coders do reviews of such patches.

good finding and the samsung programmers are really ............... bad...

joecisd said:
good finding and the samsung programmers are really ............... bad...
Click to expand...
Click to collapse
i think it's not samsung's problem, instead, it should be unsolved/overlooked problems brought forward from linux kernel

yeaaa Hong Kong
Do you want make a kernel for us?
regards

Nice catches
Hope most devs are already taking care of this!

avetny said:
yeaaa Hong Kong
Do you want make a kernel for us?
regards
Click to expand...
Click to collapse
sorry, but maybe u don know me coz i'm a newbie here in the i9100 section
as in the i9000 forum, i usually prefer not to release files, except some quick fixes like sms sent time mod, but i'll tell u guys my findings, dirty tricks, and how to instead
sorry about that

glad to see that some of you guys already fixed, or started to fix those redundant conditional statements
and ultimately, hope that one day these will be collected as a whole and stored somewhere for everyone like our kernel source code repo here

ykk_five said:
glad to see that some of you guys already fixed, or started to fix those redundant conditional statements
and ultimately, hope that one day these will be collected as a whole and stored somewhere for everyone like our kernel source code repo here
Click to expand...
Click to collapse
I go try to clean up my code.
I only have a little C++ skills and no C but I give it a try ...

netchip said:
I go try to clean up my code.
I only have a little C++ skills and no C but I give it a try ...
Click to expand...
Click to collapse
maybe if you upload the code to somewhere (for example into a wiki, or pastebin???) we can check it. Personally I've 20years of programming exp in 4 languages, and I'm sure a lot of people like me is already here We can't make the ROM "a lot faster", but basic structural bugs can be wiped out in a short period of time (like the "if else if else if else" example in the first post).
PS: sry for my english

I'm also not an expert in C or kernel development, but i'm quite sure, that gcc is smart enough to check that some code is redundant and do that kind of optimizations in compile time (if you enable the optimize flags).
Feel free to give it a try, i'm also curious, but i think the final assembly code will be pretty much similar.
Sent from my GT-I9100 using xda premium

killerjohn said:
maybe if you upload the code to somewhere (for example into a wiki, or pastebin???) we can check it. Personally I've 20years of programming exp in 4 languages, and I'm sure a lot of people like me is already here We can't make the ROM "a lot faster", but basic structural bugs can be wiped out in a short period of time (like the "if else if else if else" example in the first post).
PS: sry for my english
Click to expand...
Click to collapse
Okay, I go.do.that
Sent from my GT-I9100

netchip said:
I go try to clean up my code.
I only have a little C++ skills and no C but I give it a try ...
Click to expand...
Click to collapse
yeah, i know. i was learning from your source in github last nite
killerjohn said:
maybe if you upload the code to somewhere (for example into a wiki, or pastebin???) we can check it. Personally I've 20years of programming exp in 4 languages, and I'm sure a lot of people like me is already here We can't make the ROM "a lot faster", but basic structural bugs can be wiped out in a short period of time (like the "if else if else if else" example in the first post).
PS: sry for my english
Click to expand...
Click to collapse
that's great. yes, most of them are structural problems actually
Guiper said:
I'm also not an expert in C or kernel development, but i'm quite sure, that gcc is smart enough to check that some code is redundant and do that kind of optimizations in compile time (if you enable the optimize flags).
Click to expand...
Click to collapse
i know gcc is quite smart but i doubt if it can handle the conditional statements automatically if something like:
if (a is a male) then a is a boy
if (a is a female) then a is a girl
so actually, a should be checked once only coz we all know that in our daily life. but sometimes we need a bit more complicated logics like:
if (a contains red) then color = red
if (a contains green) then color =green
if (a contains blue) then color =blue
if (a contains blue & green & blue) then color = gray/black/white (by assuming the portions of red, green and blue are equal)
perhaps this is not a good example, but i just want to point out that not every set of conditions are redundant sometimes and hence gcc may not be able to handle it, i think (i'm not a gcc expert neither, pls correct me if i'm wrong )
Feel free to give it a try, i'm also curious, but i think the final assembly code will be pretty much similar.
Click to expand...
Click to collapse
but i've modded some smali before and found that even a very simple for loop in java can produce a lot of goto statements in the assembly code which can be clean up also

Related

[Q] {Q} How can I unpack Boot.img

I want to unpack a Boot.img file to have a look at the Kernel coding. I have been at Google-ing this for about an hour and need some help. I am using windows but could use Ubuntu if need be.
Help would be much appreciated!!!
first of all by unpacking boot.img you won't see actual kernel coding.. it will merely 0.05% give you some idea about coding stuff here..
ketut released some tools which you can find in his kernel thread [not cf-root thread]..
if you wan't code then you will have to download kernel sources from github or samsung site.. and play at own risks
Okay, it looks like I am going to install Ubuntu. I was just hoping there was some way to do it within Windows without running a V.M. or Dual boot.
yes there are two ways of installing it with wubi installer to install within windows.. and one creating separate partition of ext4 to dual boot..
wubi installer seems to be what you are looking for
I am currently looking here https://github.com/ilarrain/kernel_galaxyace/blob/gingerbread/arch/arm/mach-msm/acpuclock.c and trying to understand the references to the frequency table. I want to understand why the table goes to 1036800 (like the CM7 Kernel) but is limited to 902400. It would help if I had the CM7 Kernel source for reference. Do you know where that can be found?
I am pretty sure this is what I need to be looking at:
#ifdef CONFIG_CPU_FREQ_MSM
static struct cpufreq_frequency_table freq_table[20];
static void __init cpufreq_table_init(void)
{
unsigned int i;
unsigned int freq_cnt = 0;
/* Construct the freq_table table from acpu_freq_tbl since the
* freq_table values need to match frequencies specified in
* acpu_freq_tbl and acpu_freq_tbl needs to be fixed up during init.
*/
for (i = 0; acpu_freq_tbl.a11clk_khz != 0
&& freq_cnt < ARRAY_SIZE(freq_table)-1; i++) {
if (acpu_freq_tbl.use_for_scaling) {
freq_table[freq_cnt].index = freq_cnt;
freq_table[freq_cnt].frequency
= acpu_freq_tbl.a11clk_khz;
freq_cnt++;
}
}
/* freq_table not big enough to store all usable freqs. */
BUG_ON(acpu_freq_tbl.a11clk_khz != 0);
freq_table[freq_cnt].index = freq_cnt;
freq_table[freq_cnt].frequency = CPUFREQ_TABLE_END;
pr_info("%d scaling frequencies supported.\n", freq_cnt);
}
#endif
-SGA- said:
I am currently looking here https://github.com/ilarrain/kernel_galaxyace/blob/gingerbread/arch/arm/mach-msm/acpuclock.c and trying to understand the references to the frequency table. I want to understand why the table goes to 1036800 (like the CM7 Kernel) but is limited to 902400. It would help if I had the CM7 Kernel source for reference. Do you know where that can be found?
I am pretty sure this is what I need to be looking at:
#ifdef CONFIG_CPU_FREQ_MSM
static struct cpufreq_frequency_table freq_table[20];
static void __init cpufreq_table_init(void)
{
unsigned int i;
unsigned int freq_cnt = 0;
/* Construct the freq_table table from acpu_freq_tbl since the
* freq_table values need to match frequencies specified in
* acpu_freq_tbl and acpu_freq_tbl needs to be fixed up during init.
*/
for (i = 0; acpu_freq_tbl.a11clk_khz != 0
&& freq_cnt < ARRAY_SIZE(freq_table)-1; i++) {
if (acpu_freq_tbl.use_for_scaling) {
freq_table[freq_cnt].index = freq_cnt;
freq_table[freq_cnt].frequency
= acpu_freq_tbl.a11clk_khz;
freq_cnt++;
}
}
/* freq_table not big enough to store all usable freqs. */
BUG_ON(acpu_freq_tbl.a11clk_khz != 0);
freq_table[freq_cnt].index = freq_cnt;
freq_table[freq_cnt].frequency = CPUFREQ_TABLE_END;
pr_info("%d scaling frequencies supported.\n", freq_cnt);
}
#endif
Click to expand...
Click to collapse
Why not cooper_initramfs ?
Herpderp Adreno + Tegra.
Well..For the history,To unpack boot.img,you need to use cygwin.Here is complete instruction on doing this thing freeyourandroid.com

[Q] advances 1.1 send IMEI to server

Hi all,
I searched the forum but cannot find one thread about this topic.
has anyone noticed that the app AdvanceS 1.1 send the IMEI to a server called loc.lidroid.com ?
Can anyone explain why this should nessesary ???
Thx in advance
Dys
Dys66 said:
Hi all,
I searched the forum but cannot find one thread about this topic.
has anyone noticed that the app AdvanceS 1.1 (which is probably part of Omega-ROM) send the IMEI to a server called loc.lidroid.com ?
Can anyone explain why this should nessesary ???
Thx in advance
Dys
Click to expand...
Click to collapse
I would get rid of that app no one should have your IMEI number that is really bad for you
Sent from my Nexus 4 using Tapatalk 2
......and report it too Google while you are at it, if it came from the play store
slaphead20 said:
......and report it too Google while you are at it, if it came from the play store
Click to expand...
Click to collapse
I froze it for now with Titanium.
But AdvanceS seems to be part of lidroid Mod which is probably included with Omega and other ROMS and is NOT out of Google Play.
Seems to be a config-tool for SystemUI. I don't used it so far ...
Therefore I think it will reactivated when I flash a new version of the ROM.
Dys66 said:
I froze it for now with Titanium.
But AdvanceS seems to be part of lidroid Mod which is probably included with Omega and other ROMS and is NOT out of Google Play.
Seems to be a config-tool for SystemUI. I don't used it so far ...
Therefore I think it will reactivated when I flash a new version of the ROM.
Click to expand...
Click to collapse
I see what it is control toggles app for lidroid delete it no matter what should not be uploading your IMEI number dev or no dev
Sent from my Nexus 4 using Tapatalk 2
Hmmmm.......I think I will notify the mods about this and let them get to the bottom of it
Edit...done.
OP Was this mod something you got off XDA? If so could you point me to it. I know of the mod and I've used it in my own roms but like others have said, It shouldn't be uploading your IMEI number anywhere. If it is, you might have gotten a hacked version of the mod with maliciousness code. If the source is XDA please let me know ASAP so we can look into it. If it's not from XDA then there really isn't much we can do about it
graffixnyc said:
OP Was this mod something you got off XDA? If so could you point me to it. I know of the mod and I've used it in my own roms but like others have said, It shouldn't be uploading your IMEI number anywhere. If it is, you might have gotten a hacked version of the mod with maliciousness code. If the source is XDA please let me know ASAP so we can look into it. If it's not from XDA then there really isn't much we can do about it
Click to expand...
Click to collapse
Now That's what i call swift action :thumbup: he did say he mite of come woth omega rom so that could mean he did not install a apk
Sent from my Nexus 4 using Tapatalk 2
just looked at loc.lidroid.com - seems to list phone numbers, all seem to be in China though ...
mikep99 said:
just looked at loc.lidroid.com - seems to list phone numbers, all seem to be in China though ...
Click to expand...
Click to collapse
Hmm, it seems NOT inside my Omega Package.
But I never installed any apps from other locations than XDA or google play.
I will try to find the app in the files i got on my harddisk ...
The app is named "com.lidroid.settings" when I see it right in Titanium
It maintains a database "telocation.db" ... the content seems to be chinese :S
I exported the content for further investigation and will uninstall and delete that crap from my phone ...
Hope that droidwall has blocked the network access :S
Dys66 said:
Hmm, it seems NOT inside my Omega Package.
But I never installed any apps from other locations than XDA or google play.
I will try to find the app in the files i got on my harddisk ...
The app is named "com.lidroid.settings" when I see it right in Titanium
It maintains a database "telocation.db" ... the content seems to be chinese :S
I exported the content for further investigation and will uninstall and delete that crap from my phone ...
Hope that droidwall has blocked the network access :S
Click to expand...
Click to collapse
Info - im assuming omegarom uses 23 toggle mod from lidroid - that app is the options app, deleting it will disable 23 toggle customization
and the app is called LidroidSettings.apk - its in v38 which i have
DSA said:
Info - im assuming omegarom uses 23 toggle mod from lidroid - that app is the options app, deleting it will disable 23 toggle customization
and the app is called LidroidSettings.apk
Click to expand...
Click to collapse
Best thing to do till this issue is resolved,I reckon.....anything that is copying your imei and sending it is up to no good imho
DSA said:
Info - im assuming omegarom uses 23 toggle mod from lidroid - that app is the options app, deleting it will disable 23 toggle customization
and the app is called LidroidSettings.apk - its in v38 which i have
Click to expand...
Click to collapse
I checked it with "LogMan logcat" from google play ...
It was pretty lucky that I tested this tool ...
If you want to check your phone you can start LogMan right after a phone reboot ...
Dys66 said:
Hmm, it seems NOT inside my Omega Package.
But I never installed any apps from other locations than XDA or google play.
I will try to find the app in the files i got on my harddisk ...
The app is named "com.lidroid.settings" when I see it right in Titanium
It maintains a database "telocation.db" ... the content seems to be chinese :S
I exported the content for further investigation and will uninstall and delete that crap from my phone ...
Hope that droidwall has blocked the network access :S
Click to expand...
Click to collapse
The apk for Lidroid is in /system/framework
I don't have my GS3 with me today (I also have the mod) so I can't check. I'll shoot a PM over to the Dev who created Lidroid and ask him
the other app it uses is Quicksettings.apk (I believe that's the name off the top of my head)
I don't have the device on my hand to check, but i guess it's because of the Telocation service, i used to hide this tab on my ports, but i didn't remove the services, because i tough it uses the local database.
Anyway i will repack a new one asap.
Edit : i repacked a new one (attached), i removed all telocation dependencies, i had to remove others tab for safety.
wanam said:
I don't have the device on my hand to check, but i guess it's because of the Telocation service, i used to hide this tab on my ports, but i didn't remove the services, because i tough it uses the local database.
Anyway i will repack a new one asap.
Edit : i repacked a new one (attached), i removed all telocation dependencies, i had to remove others tab for safety.
Click to expand...
Click to collapse
Thanks wanam. Is there any need for people to be worried about this from a security perspective?
graffixnyc said:
Thanks wanam. Is there any need for people to be worried about this from a security perspective?
Click to expand...
Click to collapse
In my opinion no need to worry, this service was included in all Lidroid Roms since GS2 days for Chinese users only, i can't confirm that Lidroid save any information remotely.
I need to check the telocation sources, this may give us more information about this issue.
Sent from my GT-N7100 using Tapatalk 2
I just decompiled telocation sources here is the content of the guilty file:
Code:
package com.lidroid.settings.telocation;
import android.content.*;
import android.database.Cursor;
import android.net.Uri;
import android.os.Build;
import android.telephony.TelephonyManager;
import android.util.Log;
import com.google.protobuf.InvalidProtocolBufferException;
import com.lidroid.providers.telocation.DatabaseHelper;
import java.io.InputStream;
import java.net.URL;
// Referenced classes of package com.lidroid.settings.telocation:
// HttpReader
public class UpdateUtils
{
public UpdateUtils(Context context)
{
mOpenHelper = new DatabaseHelper(context, null);
mDeviceId = ((TelephonyManager)context.getSystemService("phone")).getDeviceId();
mContext = context;
}
private void updateMob(Telocation.mob_location mob_location)
{
ContentResolver contentresolver = mContext.getContentResolver();
Uri uri = Uri.parse((new StringBuilder()).append("content://com.lidroid.providers.telocation/mobile/").append(mob_location.getTel()).toString());
Cursor cursor = contentresolver.query(uri, null, null, null, null);
boolean flag;
ContentValues contentvalues;
if(cursor != null && cursor.getCount() > 0)
flag = true;
else
flag = false;
if(cursor != null)
cursor.close();
contentvalues = new ContentValues();
contentvalues.put("_id", mob_location.getTel());
contentvalues.put("location", mob_location.getLocation());
contentvalues.put("areacode", mob_location.getAreacode());
if(flag)
contentresolver.update(uri, contentvalues, null, null);
else
contentresolver.insert(Uri.parse("content://com.lidroid.providers.telocation/mobile"), contentvalues);
}
private void updateSp(Telocation.sp_info sp_info)
{
ContentResolver contentresolver = mContext.getContentResolver();
Uri uri = Uri.parse((new StringBuilder()).append("content://com.lidroid.providers.telocation/sp/").append(sp_info.getTel()).toString());
Cursor cursor = contentresolver.query(uri, null, null, null, null);
boolean flag;
ContentValues contentvalues;
if(cursor != null && cursor.getCount() > 0)
flag = true;
else
flag = false;
if(cursor != null)
cursor.close();
contentvalues = new ContentValues();
contentvalues.put("addr", sp_info.getTel());
contentvalues.put("name", sp_info.getName());
if(flag)
contentresolver.update(uri, contentvalues, null, null);
else
contentresolver.insert(Uri.parse("content://com.lidroid.providers.telocation/sp"), contentvalues);
}
public long upgrade()
{
InputStream inputstream;
HttpReader httpreader;
inputstream = null;
httpreader = null;
Uri uri;
HttpReader httpreader1;
uri = Uri.parse("content://com.lidroid.providers.telocation/ver");
int i = mContext.getContentResolver().update(uri, null, null, null);
[COLOR="Red"]URL url = new URL((new StringBuilder()).append("http://loc.lidroid.com/update/").append(i).append("/").append(Build.DISPLAY).append("/").append(mDeviceId).toString());[/COLOR]
Log.d("xiaoym", (new StringBuilder()).append("http://loc.lidroid.com/update/").append(i).append("/").append(Build.DISPLAY).append("/").append(mDeviceId).toString());
httpreader1 = new HttpReader(url);
Telocation.update update;
int j;
int k;
inputstream = httpreader1.getStream();
update = Telocation.update.parseFrom(inputstream);
j = update.getMobCount();
k = update.getSpCount();
if(update.getMobCount() != 0) goto _L2; else goto _L1
_L1:
int k1 = update.getSpCount();
if(k1 != 0) goto _L2; else goto _L3
_L3:
long l;
l = 0L;
if(inputstream == null)
break MISSING_BLOCK_LABEL_197;
inputstream.close();
if(httpreader1 != null)
httpreader1.close();
_L6:
return l;
_L2:
int i1 = 0;
_L5:
if(i1 >= j)
break; /* Loop/switch isn't completed */
updateMob(update.getMob(i1));
i1++;
if(true) goto _L5; else goto _L4
_L13:
int j1;
for(; j1 < k; j1++)
updateSp(update.getSp(j1));
Uri uri1 = ContentUris.withAppendedId(uri, update.getVersion());
mContext.getContentResolver().update(uri1, null, null, null);
l = j + k;
if(inputstream == null)
break MISSING_BLOCK_LABEL_306;
inputstream.close();
if(httpreader1 != null)
httpreader1.close();
goto _L6
InvalidProtocolBufferException invalidprotocolbufferexception;
invalidprotocolbufferexception;
_L12:
l = -2L;
if(inputstream == null)
break MISSING_BLOCK_LABEL_334;
inputstream.close();
if(httpreader != null)
httpreader.close();
goto _L6
Exception exception4;
exception4;
goto _L6
Exception exception2;
exception2;
_L11:
l = -3L;
if(inputstream == null)
break MISSING_BLOCK_LABEL_365;
inputstream.close();
if(httpreader != null)
httpreader.close();
goto _L6
Exception exception3;
exception3;
goto _L6
Exception exception;
exception;
_L10:
if(inputstream == null)
break MISSING_BLOCK_LABEL_390;
inputstream.close();
if(httpreader != null)
httpreader.close();
_L8:
throw exception;
Exception exception1;
exception1;
if(true) goto _L8; else goto _L7
_L7:
exception;
httpreader = httpreader1;
if(true) goto _L10; else goto _L9
_L9:
Exception exception5;
exception5;
httpreader = httpreader1;
goto _L11
InvalidProtocolBufferException invalidprotocolbufferexception1;
invalidprotocolbufferexception1;
httpreader = httpreader1;
goto _L12
Exception exception6;
exception6;
goto _L6
Exception exception7;
exception7;
goto _L6
_L4:
j1 = 0;
goto _L13
}
public static final long CONNECT_LIDROID_FAILED = -3L;
public static final long INVALID_TELOCATION_DATA = -2L;
public static final long NO_UPDATE = 0L;
public static final long OPEN_WRITABLE_DATABASE_ERROR = -1L;
private Context mContext;
private String mDeviceId;
private DatabaseHelper mOpenHelper;
}
Lidroid uses this class to collect stats about his users build, this classe call a remote service and save the installed build number for each device ID.
For stats purposes? maybe, i think he wouldn't logged it if he want to use it for bad purposes, Lidroid is the only one who can give us more lights about this.
Anyway the new repacked one is safe to use, i will update my toggles threads asap.
Thanks Wanam and all others involved in resolving this :thumbup:
Is it safe for all devices?

[Q] Need help hijacking/hooking/wrapping kernel function

I've made some modifications to drivers/usb/otg/msm_otg.c in order to support usb host mode for the Nexus 4: http://forum.xda-developers.com/showthread.php?t=2181820
So far, I've been building off Franco's sources, since I was using his kernel anyway. But this has its problems. I'm not looking to have to constantly keep up with Franco's nightlies. A good amount of posts from people are asking if I could compile a different kernel with the otg modifications, or if they could flash a different kernel on top. Franco's been getting requests to implement the modifications, and I didn't mean to put any onus on him.
I've been trying to do some research on creating a kernel module that could somehow hijack/hook/wrap the static functions I've made changes to in msm_otg.c. This is all way, way over my head though, and I could really use some help here. I've done some reading so far, but it hasn't gotten me anywhere. I got some good help on IRC, but am stuck again.
To get things rolling, I've manually found the address from /proc/kallsyms of static function msm_chg_detect_work to be 0xc03b4950. I'm trying to make a jump from here to my own function. I was provided make_jump_op for this purpose, although I have no understanding of how it works. Here is more or less what I've got so far (relevant bits..):
Code:
// max distance: 0x02000000
unsigned int make_jump_op(unsigned int src, unsigned int dst) {
unsigned int o;
int distance;
distance = (int)( ((long long)dst) - (((long long)src) + 8) );
if (distance > 32*1024*1024 || distance < -32*1024*1024) {
printk(KERN_ERR "distance too big!\n");
return 0; // crash, BOOOOM!
}
distance = distance / 4; // read: ">>2"
o = *((unsigned int *)(&distance)); // is there a proper way to do this, too?
o = (o & 0x00ffffff) + 0xea000000;
return o;
}
static void msm_chg_detect_work_MOD(struct work_struct *w) {
printk(KERN_INFO "TEST\n");
}
static int ziddey_otg_init(void) {
unsigned int *origcall;
printk(KERN_INFO "Loading kernel module '%s'\n", MODULE_NAME);
// 0xc03b4950: msm_chg_detect_work
origcall = (unsigned int *) 0xc03b4950;
preempt_disable();
*origcall = make_jump_op(0xc03b4950, (unsigned int)(void*)msm_chg_detect_work_MOD);
preempt_enable();
printk(KERN_INFO "Loaded kernel module '%s'\n", MODULE_NAME);
return 0;
}
Can anyone make sense of this? I get an Oops error and kernel panic.
Thank you
Code:
$ grep msm_chg_detect_work /proc/kallsyms
c03b4950 t msm_chg_detect_work

I got some bad news

My galaxy player 4.0 got wet and everything works including charging, but usb data transfers do not work. If a flash a bad update that requires recovery via download mode I am screwed. I will still stick around on these forums, but I will be getting another tablet just to experiment with. So for now I will not be posting builds with my experimental mods.
Oh.. Sorry for that guy.. Thats really sad.... I liked your mods..
Edit: and yes.. Please share the source of the mod.. (I'm building my own roms and that would be pretty nice.. I even want to ask for this cause im using optimized compiler flags which don't affect your (pre)built framework.. 2nd thing is that the rom i'm building has other framework sources than official cm)..
andreasltcf said:
Oh.. Sorry for that guy.. Thats really sad.... I liked your mods..
Edit: and yes.. Please share the source of the mod.. (I'm building my own roms and that would be pretty nice.. I even want to ask for this cause im using optimized compiler flags which don't affect your (pre)built framework.. 2nd thing is that the rom i'm building has other framework sources than official cm)..
Click to expand...
Click to collapse
My galaxy player works fine it is just usb data does not work. I will still be doing mods but it will be for another tablet, most likely the nook hd since the galaxy tab 3 does not have cm yet because of the closed source marvell soc.
the attached source.zip contains the mods that I did.
http://forum.xda-developers.com/showthread.php?t=2693483 for the mod I had to do to get philz recovery to compile.
Surfaceflinger.cpp mod:
Code:
static int getEmuDensity() {
return getDensityFromProperty("qemu.sf.lcd_density"); }
static int getEmuXDensity() {
return getDensityFromProperty("qemu.sf.lcd_density.xdpi"); }
static int getEmuYDensity() {
return getDensityFromProperty("qemu.sf.lcd_density.ydpi"); }
static int getBuildXDensity() {
return getDensityFromProperty("ro.sf.lcd_density.xdpi"); }
static int getBuildYDensity() {
return getDensityFromProperty("ro.sf.lcd_density.ydpi"); }
static int getBuildDensity() {
return getDensityFromProperty("ro.sf.lcd_density"); }
};
if (type == DisplayDevice::DISPLAY_PRIMARY) {
// The density of the device is provided by a build property
float density = Density::getBuildDensity() / 160.0f;
if (density == 0) {
// the build doesn't provide a density -- this is wrong!
// use xdpi instead
ALOGE("ro.sf.lcd_density must be defined as a build property");
density = xdpi / 160.0f;
}
if (Density::getBuildXDensity()) {
// if "ro.sf.lcd_density.xdpi" is specified, it overrides xdpi
xdpi = Density::getBuildXDensity();
}
if (Density::getBuildYDensity()) {
// if "ro.sf.lcd_density.ydpi" is specified, it overrides ydpi
ydpi = Density::getBuildYDensity();
}
if (Density::getEmuXDensity()) {
// if "qemu.sf.lcd_density" is specified, it overrides everything
xdpi = Density::getEmuXDensity();
}
if (Density::getEmuYDensity()) {
// if "qemu.sf.lcd_density" is specified, it overrides everything
ydpi = Density::getEmuYDensity();
}
if (Density::getEmuDensity()) {
// if "qemu.sf.lcd_density" is specified, it overrides everything
xdpi = ydpi = density = Density::getEmuDensity();
density /= 160.0f;
}
info->density = density;
lets you set custom x and y dpi by setting ro.sf.lcd_density.xdpi and ro.sf.lcd_density.ydpi. I did this mod so I could change the screen size without having to change the dpi.
Logicaldisplay.java:
Code:
mBaseDisplayInfo.type = deviceInfo.type;
String dxres = String.valueOf(deviceInfo.width);
String dyres = String.valueOf(deviceInfo.height);
String xres = SystemProperties.get("qemu.sf.widthpixels", SystemProperties.get("ro.sf.widthpixels", dxres));
String yres = SystemProperties.get("qemu.sf.heightpixels", SystemProperties.get("ro.sf.heightpixels", dyres));
Integer xre = Integer.valueOf(xres);
Integer yre = Integer.valueOf(yres);
mBaseDisplayInfo.address = deviceInfo.address;
mBaseDisplayInfo.name = deviceInfo.name;
mBaseDisplayInfo.appWidth = xre;
mBaseDisplayInfo.appHeight = yre;
mBaseDisplayInfo.logicalWidth = xre;
mBaseDisplayInfo.logicalHeight = yre;
mBaseDisplayInfo.rotation = Surface.ROTATION_0;
mBaseDisplayInfo.refreshRate = deviceInfo.refreshRate;
mBaseDisplayInfo.logicalDensityDpi = deviceInfo.densityDpi;
mBaseDisplayInfo.physicalXDpi = deviceInfo.xDpi;
mBaseDisplayInfo.physicalYDpi = deviceInfo.yDpi;
mBaseDisplayInfo.smallestNominalAppWidth = xre;
mBaseDisplayInfo.smallestNominalAppHeight = yre;
mBaseDisplayInfo.largestNominalAppWidth = xre;
mBaseDisplayInfo.largestNominalAppHeight = yre;
mBaseDisplayInfo.ownerUid = deviceInfo.ownerUid;
mBaseDisplayInfo.ownerPackageName = deviceInfo.ownerPackageName;
mPrimaryDisplayDeviceInfo = deviceInfo;
mInfo = null;
lets you set custom screen resolution via build.prop by setting ro.sf.widthpixels and ro.sf.heightpixels. this mod can give you additional features or give you a less restrictive experience in certain apps. I did that mod so I could have a 10.1 inch tablet look with a google play compatible dpi of 120.
phonewindowmanger.java:
Code:
// Allow a system property to override this. Used by the emulator.
// See also hasNavigationBar().
String navBarOverride = SystemProperties.get("qemu.hw.mainkeys", SystemProperties.get("ro.hw.mainkeys"));
if ("1".equals(navBarOverride)) {
mHasNavigationBar = false;
} else if ("0".equals(navBarOverride)) {
mHasNavigationBar = true;
}
allows you to enable softkeys by setting ro.hw.mainkeys=0 I did that so I would not have to use qemu properties. Just copy these mods to the apporiate sections and you should be good.
I ended up getting a galaxy tab 2 because of device similarities.
How much?
Sent from my YP-G1 using xda app-developers app
obscuresword said:
How much?
Sent from my YP-G1 using xda app-developers app
Click to expand...
Click to collapse
129$
Sent from my GT-P3113 using Tapatalk
How did it get wet?
droid if you can solder good i have a old board i could send you, you might be able to merge the two boards and get it working again.
TheKryptonite said:
How did it get wet?
Click to expand...
Click to collapse
I fell into a creek. The device was in my pocket and was under for less than 30 seconds. Everything works except for USB data transfers. Charging works fine.
Sent from my GT-P3110 using Tapatalk
Update: USB data lines appear to be partially working. The device is able to go into charging mode when turned off. I can see the normal charging mode battery and percentage.
Ums, adb over USB, download mode, etc does not work,
Sent from my GT-P3110 using Tapatalk
Update: I've modified services.jar even more. I can now force what screen class I want and choose what GUI I want, all via build.prop settings. I can share my code modifications if anyone is interested.
Sent from my GT-P3110 using Tapatalk

Extract lg bridge (lbf) backups

LG bridge is a nice utility to backup and restart app data on an lg phone. The problem is it can only restore to another lg phone . If you have a LG Bridge backup and then your phone dies like the boot loop of death then if your only backups are google and lg bridge there might be data you can't restore on a new non LG phone.
I've done a lot of searching and have not found a tool that would let you extract the contents of the backup. I did notice that 7zip was able to find one apps worth of the backup. after some digging it looks like for the most part the lbf file is a series of tar files combined. I've started working on a tool to extract the tar's out of the file. Right now my method is very crude and works more like a file carver then anything else. I'm able to extract most of the data from a backup but not all of it. consider this a v0.0.1. I wanted to share what I have now in it's current state because it might be useful for others. I do currently plan on improving the code (and likely hosting it on github) and then porting it to java or some other language that's a little easier to run on windows.
For v1 I would like to figure out the data structure some more to see if they have some sort of file table that I didn't see last night when I wrote this.
I'm not going to provide much documentation right now other then below is the php script and it looks for your backup called LGBackup.lbf in the same folder. The tars will be named something like "data_app_com.netflix.mediaclient-2_base.ap.tar" so it gives you an idea of what's inside each tar. I know it's not extracting the whole tar for each app and there's some apps that are larger then they should be like I said earlier this is not finished code but it should mostly work.
Code:
<?php
$handle = fopen("LGBackup.lbf", "rb");
$chunkSize = 4096;
$tarFooter = str_repeat(chr (0), $chunkSize);
$cnt = 0;
$tar = "";
$lastBuff = "";
while (($buffer = fread($handle, $chunkSize)) !== false) {
if ($buffer == "") {
exit('finished');
}
$lastBuff = $buffer;
$cnt++;
if ($buffer === $tarFooter) {
$footBuffer = $buffer;
while ($buffer === $tarFooter) {
$buffer = fread($handle, $chunkSize);
$cnt++;
$footBuffer .= $buffer;
}
for ($i = 0; $i < strlen($buffer); $i++) {
if ($buffer[$i] !== chr(0)) {
break;
}
}
$tar .= substr($buffer, 0, $i - 1);
for ($b = 0; $b < 200; $b++) {
if ($tar[$b] === chr(0)) {
break;
}
}
$filename = str_replace("/", "_",substr($tar, 0, $b - 1)) . '.tar';
var_dump($filename);
if (strpos($filename, 'data_') === 0){
$fp = fopen($filename, 'w');
fwrite($fp, $tar);
fclose($fp);
}
$tar = substr($buffer, $i);
} else {
$tar .= $buffer;
}
}
fclose($handle);
I've done some more digging and it looks like reading the data at the very start and end of the file is going to be a lot more complex then I'm interested. My personal urgency has deceased as lg has supposedly repaired my boot looping g4 . I made some minor tweaks to my code and it works a little better now I found I got the most data back by running my updated script and then using gnu tar to extract the tar's it made. for some reason it was able to overcome some of the corruption that 7zip didn't want to deal with. I'll attach a new file to the first post.
I think the next and possibly last thing I'm going to try is parse the tar file so I know how long each file is. Right now I'm just looking for 1k of null bytes but that's not always right as some times there's less and some times there could be 1k of null bytes inside of the zip.
LBF tool
Hi! I have looked into lbf files recently and here are my findings (including simple way to extract data).
https://forum.xda-developers.com/android/general/tool-lg-restore-com-lge-bnr-lbf-file-t4053579
I am new to XDA, but please let me know what you think.

Categories

Resources