[Q] How to tap into CoreDLL.DLL GetSystemPowerStatusEx2 ? - Windows Mobile Software Development

Hi all,
none of the currently existing battery current (mA) meters for WindowsMobile make me really happy: acbPower, PowerMonitor 1.05, some Mortscripts...
I'd rather try to write something on my own to record and store the power usage profile, plot it somehow, do runtime prediction etc.
Apparently the data comes from CoreDLL.DLL, esp GetSystemPowerStatusEx2. The registry only stores the remaining capacity, which is of low interest to me.
Neither Mortscript nor Basic4PPC seem to able to tap into the functions of this CoreDLL, Are there 'wrapper' tools to expose these functions to them somehow?
How to I skin this cat? Is there a way to embed the DLL and functions into Basic4PPC somehow? May need complex SDK tools or something, maybe out of my league?
I found the following code sniplet, probably .NET (VisualBasic, VIsualC?), but don't know how to convert it to use it in Basic4PPC, NSBasic or else?
Any ideas, suggestions - thanks!
m
[DllImport("coredll.dll", EntryPoint = "GetSystemPowerStatusEx2", SetLastError = true)]
private static extern uint GetSystemPowerStatusEx2(_SYSTEM_POWER_STATUS_EX2 pSystemPowerStatusEx2,
uint dwLen,
bool fUpdate);
public bool MS_GetSystemPowerStatusEx2()
{
bool ret_value = false;
if (MSAPIWrapperStart == false)
{
return true;
}
if (GetSystemPowerStatusEx2(SystemPowerStatusEX2,
(uint)Marshal.SizeOf(typeof(_SYSTEM_POWER_STATUS_E X2)),
false) != 0)
{
ret_value = true;
}
return ret_value;
}
public struct _SYSTEM_POWER_STATUS_EX2
{
public byte ACLineStatus;
public byte BatteryFlag;
public byte BatteryLifePercent;
public byte Reserved1;
public uint BatteryLifeTime;
public uint BatteryFullLifeTime;
public byte Reserved2;
public byte BackupBatteryFlag;
public byte BackupBatteryLifePercent;
public byte Reserved3;
public uint BackupBatteryLifeTime;
public uint BackupBatteryFullLifeTime;
public uint BatteryVoltage;
public uint BatteryCurrent;
public uint BatteryAverageCurrent;
public uint BatteryAverageInterval;
public uint BatterymAHourConsumed;
public uint BatteryTemperature;
public uint BackupBatteryVoltage;
public byte BatteryChemistry;
[MarshalAs(UnmanagedType.ByValArray, SizeConst=128)]
public byte[] ExtraInfo;
}
private _SYSTEM_POWER_STATUS_EX2 SystemPowerStatusEX2;
SystemPowerStatusEX2 = new _SYSTEM_POWER_STATUS_EX2();

Related

Using Provxml to add accents.

I've been trying to add a custom accent to my Focus S. Most tools available don't yet work (advance config is one) but the interlop unlock by using a provxml does work.
I've tried this
Code:
<wap-provisioningdoc>
<characteristic type="Registry">
<characteristic type="HKLM\ControlPanel\Themes\1\Accents">
<parm name="11" value="4286808708" datatype="integer" />
</characteristic>
<characteristic type="HKLM\ControlPanel\Themes\0\Accents">
<parm name="11" value="4286808708" datatype="integer" />
</characteristic>
<characteristic type="HKLM\ControlPanel\Themes\AccentsDisplayName\ 0409">
<parm name="11" value="Gray" datatype="string" />
</characteristic>
</characteristic>
</wap-provisioningdoc>
and this to eliminate variables
Code:
<wap-provisioningdoc>
<characteristic type="Registry">
<characteristic type="HKLM\ControlPanel\Themes\1\Accents">
<parm name="1" value="-8158588" datatype="integer" />
</characteristic>
<characteristic type="HKLM\ControlPanel\Themes\0\Accents">
<parm name="1" value="-8158588" datatype="integer" />
</characteristic>
<characteristic type="HKLM\ControlPanel\Themes\AccentsDisplayName\ 0409">
<parm name="1" value="Gray" datatype="string" />
</characteristic>
<characteristic type="HKLM\ControlPanel\Themes\1\Accents">
<parm name="2" value="FF838284" datatype="integer" />
</characteristic>
<characteristic type="HKLM\ControlPanel\Themes\0\Accents">
<parm name="2" value="FF838284" datatype="integer" />
</characteristic>
<characteristic type="HKLM\ControlPanel\Themes\AccentsDisplayName\ 0409">
<parm name="2" value="Gray" datatype="string" />
</characteristic>
<characteristic type="HKLM\ControlPanel\Themes\1\Accents">
<parm name="3" value="4286808708" datatype="integer" />
</characteristic>
<characteristic type="HKLM\ControlPanel\Themes\0\Accents">
<parm name="3" value="4286808708" datatype="integer" />
</characteristic>
<characteristic type="HKLM\ControlPanel\Themes\AccentsDisplayName\ 0409">
<parm name="3" value="Gray" datatype="string" />
</characteristic>
<characteristic type="HKLM\ControlPanel\Themes\1\Accents">
<parm name="4" value="0xFF838284" datatype="integer" />
</characteristic>
<characteristic type="HKLM\ControlPanel\Themes\0\Accents">
<parm name="4" value="0xFF838284" datatype="integer" />
</characteristic>
<characteristic type="HKLM\ControlPanel\Themes\AccentsDisplayName\ 0409">
<parm name="4" value="Gray" datatype="string" />
</characteristic>
</characteristic>
</wap-provisioningdoc>
but it doesn't work.
Any help would gratefully be appreciated.
Quick question: did you save the file as Unicode? I think the Samsung tools expect Unicode provxml files. Or maybe it's the other way around, I forget.
GoodDayToDie said:
Quick question: did you save the file as Unicode? I think the Samsung tools expect Unicode provxml files. Or maybe it's the other way around, I forget.
Click to expand...
Click to collapse
I edited other provxml files that I know work. I edited them with notepad and with visual studio, lol I've tried everything.
I tried to do this myself when I had a Focus S with no success.
I wonder how Marvin_S's On-Device ProvXML TOOL gets this to work.
Hopefully he can chime in, hopefully he can get the tool working on the Focus S
ManelScout4Life said:
I wonder how Marvin_S's On-Device ProvXML TOOL gets this to work.
Hopefully he can chime in, hopefully he can get the tool working on the Focus S
Click to expand...
Click to collapse
Im using first gen dlls so a small chance it will work... Are u saying anything trough this app worked on the focus s? If non of the default edits work than dont even bother, ill need to update the app for the samsung s than.
Samsung indeed uses Unicode. Otherwise it wont work. Again there are no focus s dlls in there so idk if it will work, but let me know, otherwise I can add a focus s dll.
Marvin_S said:
Im using first gen dlls so a small chance it will work... Are u saying anything trough this app worked on the focus s? If non of the default edits work than dont even bother, ill need to update the app for the samsung s than.
Samsung indeed uses Unicode. Otherwise it wont work. Again there are no focus s dlls in there so idk if it will work, but let me know, otherwise I can add a focus s dll.
Click to expand...
Click to collapse
No, your tool does not work at all on the S, it opens but none of the functions work.
However, I can add provxml files with the filedeployer xaps.
I'm also unsure what the proper provxml file should look like for changing accents.
ManelScout4Life said:
No, your tool does not work at all on the S, it opens but none of the functions work.
However, I can add provxml files with the filedeployer xaps.
I'm also unsure what the proper provxml file should look like for changing accents.
Click to expand...
Click to collapse
As expected.
Very simple just save it in Unicode, than it should work man.
Also if you want to bind it in an app, I've found some native stuff to work with on the Samsung S
Code:
Nevermind
EDIT:
The api is listed here, there might be a way to update the app
EDIT2:
Code:
public void Initialize()
{
ComBridge.RegisterComDll("WirelessManager_SecProxyClient.dll", new Guid("6992E452-12CB-4cb7-A9C8-5CC548159A69"));
this.m_CoClass = new COSecWin32Proxy();
this.m_CoInterface = (ISecProxyWin32Interface) this.m_CoClass;
}
[ComImport, Guid("6992E452-12CB-4cb7-A9C8-5CC548159A69"), ClassInterface(ClassInterfaceType.None)]
public class COSecWin32Proxy
{
}
[ComImport, Guid("2A9C50C0-77AC-4a12-9E26-17395ADF8870"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface ISecProxyWin32Interface
{
void GetProxyVersion(out uint version);
void Reserved();
void ChekcAPI(uint apiID, out uint result);
void RegistrySetString(uint HKEY, string pwszPath, string valueName, string value);
void RegistryGetString(uint HKEY, string pwszPath, string valueName, out string value);
void RegistrySetDWORD(uint HKEY, string pwszPath, string valueName, uint value);
void RegistryGetDWORD(uint HKEY, string pwszPath, string valueName, out uint value);
void CreateFile(string lpFileName, uint dwDesiredAccess, uint dwShareMode, uint dwCreationDisposition, uint dwFlagsAndAttributes, out uint phCreateFile);
void CloseHandle(uint hObject);
void ReadFile(uint hFile, out byte[] lpBuffer, uint nNumberOfBytesToRead, out uint lpNumberOfBytesRead);
void WriteFile(uint hFile, byte[] lpBuffer, uint nNumberOfBytesToWrite, out uint lpNumberOfBytesWritten);
void GetFileSize(uint hFile, out uint lpFileSizeHigh);
void CopyFile(string lpExistingFileName, string lpNewFileName, int bFailIfExists);
void DeleteFile(string lpFileName);
void LaunchExe(string szExe, string szArg);
}
Should be the code Ill need to add to the app (not sure if it will work though, ill have to scan the app further).
Marvin_S said:
As expected.
Very simple just save it in Unicode, than it should work man.
Also if you want to bind it in an app, I've found some native stuff to work with on the Samsung S
Code:
namespace Samsung.Phone.Native
{
public class Con
{
// Fields
private COSecCONProxy m_CoClass;
private ISecProxyCONInterface m_CoInterface;
private static Con m_single;
// Methods
static Con();
private Con();
public static void BluetoothCloseAudio();
public static void BluetoothOpenAudio();
public static ISecProxyCONInterface CallInterface();
public ISecProxyCONInterface GetComInterface();
public static Con GetInstance();
public static void GetRadioState(int device, out bool state);
public static void GetWirelessState(out bool state);
public void Initialize();
public static void SetRadioState(int device, bool state);
public static void SetWirelessState(bool state);
public static void WlanGetIpInfo(out string IpAddr, out string Subnet, out string Gateway, out string Dns, out string Wins, out bool DhcpMode);
public static void WlanGetStatus(out string macAddr, out string ssid, out int status, out int rssi, out int security);
public static void WlanSetIpInfo(string IpAddr, string Subnet, string Gateway, string Dns, string Wins, bool DhcpMode);
}
[ComImport, ClassInterface(ClassInterfaceType.None), Guid("3E16DD96-1BB8-4ed4-A74F-EE16307A147E")]
public class COSecCONProxy
{
}
[ComImport, ClassInterface(ClassInterfaceType.None), Guid("89DE267C-9F5A-43f5-895C-B891F0F64C6E")]
public class COSecRILProxy
{
}
[ComImport, Guid("A1EF1A51-6156-4882-A9D3-202881BC7A05"), ClassInterface(ClassInterfaceType.None)]
public class COSecSYSProxy
{
}
[ComImport, Guid("6992E452-12CB-4cb7-A9C8-5CC548159A69"), ClassInterface(ClassInterfaceType.None)]
public class COSecWin32Proxy
{
}
[ComImport, Guid("9ADD1CCA-FB7B-4f31-A496-9FC565DB0272"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface ISecProxyCONInterface
{
void GetProxyVersion(out uint version);
void Reserved();
void ChekcAPI(uint apiID, out uint result);
void WlanGetIpInfo(out string IpAddr, out string Subnet, out string Gateway, out string Dns, out string Wins, out bool DhcpMode);
void WlanSetIpInfo(string IpAddr, string Subnet, string Gateway, string Dns, string Wins, bool DhcpMode);
void WlanGetStatus(out string macAddr, out string ssid, out int status, out int rssi, out int security);
void SetRadioState(int device, bool state);
void GetRadioState(int device, out bool state);
void SetWirelessState(bool state);
void GetWirelessState(out bool state);
void BluetoothOpenAudio();
void BluetoothCloseAudio();
}
[ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("CA785B58-3211-46ee-B2B8-13F0CFA18C17")]
public interface ISecProxyRILInterface
{
void GetProxyVersion(out uint version);
void Reserved();
void ChekcAPI(uint apiID, out uint result);
void GetIMSI(out string IMSI);
void GetIMEI(out string IMEI);
void GetLockingStatus(uint m_dwLockFacility, out uint pdwLockStatus, out uint pdwResult);
void GetCallWaitingStatus(out uint pdwInfoClass, out uint pdwResult);
void SetCallWaitingStatus(uint dwInfoClass, uint dwStatus, out uint pdwResult);
void GetOperatorList([MarshalAs(UnmanagedType.SafeArray)] out byte[] info, out uint pdwCount, out uint pdwResult);
void SetCurrentOperator(uint dwMode, IntPtr info, out uint pdwResult);
void GetCallForwardingSettings(uint dwReason, uint dwAddressID, out uint pdwStatus, out uint pdwNumType, out string pwszAddress, out uint pdwDelayTime, out uint pdwResult);
void AddCallForwardingSettings(uint dwReason, uint dwInfoClass, string wszAddress, uint dwDelayTime, out uint pdwResult);
void RemoveCallForwardingSettings(uint dwReason, uint dwInfoClass, out uint pdwResult);
void RIL_Devspecific2DWORD(uint dwCmdID, out uint pdwParam1, out uint pdwParam2, out uint pdwResult);
void GetCallBarringStatus(uint dwType, uint dwInfoClass, string szPassword, out uint pdwBarringStatus, out uint pdwResult);
void SetCallBarringStatus(uint dwType, uint dwInfoClass, string szPassword, uint dwBarringStatus, out uint pdwResult);
void GetAudioMute(out uint dwEnable);
void SetAudioMute(uint dwEnable);
void Hangup();
void PerformImeiCompare(out string strSalesCode, out uint dwResult, out string strErrorMessage);
void SetLockingStatus(uint m_dwLockFacility, string pPasswd, out uint m_dwStatus, out uint pdwResult);
void CallBlockerUpdateInfo(string pwszUpdatedUserInfo, uint dwOpMode, out uint dwResult);
void GetCBConfig(out uint dwTotal, out uint dwSize, out byte[] lpBuffer);
void SetCBConfig(uint dwTotal, uint dwSize, byte[] lpBuffer);
}
[ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("E05255E0-ED8F-4898-B3C3-4F8C5E29A2C1")]
public interface ISecProxySYSInterface
{
void ChekcAPI(uint apiID, out uint result);
}
[ComImport, Guid("2A9C50C0-77AC-4a12-9E26-17395ADF8870"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface ISecProxyWin32Interface
{
void GetProxyVersion(out uint version);
void Reserved();
void ChekcAPI(uint apiID, out uint result);
void RegistrySetString(uint HKEY, string pwszPath, string valueName, string value);
void RegistryGetString(uint HKEY, string pwszPath, string valueName, out string value);
void RegistrySetDWORD(uint HKEY, string pwszPath, string valueName, uint value);
void RegistryGetDWORD(uint HKEY, string pwszPath, string valueName, out uint value);
void CreateFile(string lpFileName, uint dwDesiredAccess, uint dwShareMode, uint dwCreationDisposition, uint dwFlagsAndAttributes, out uint phCreateFile);
void CloseHandle(uint hObject);
void ReadFile(uint hFile, out byte[] lpBuffer, uint nNumberOfBytesToRead, out uint lpNumberOfBytesRead);
void WriteFile(uint hFile, byte[] lpBuffer, uint nNumberOfBytesToWrite, out uint lpNumberOfBytesWritten);
void GetFileSize(uint hFile, out uint lpFileSizeHigh);
void CopyFile(string lpExistingFileName, string lpNewFileName, int bFailIfExists);
void DeleteFile(string lpFileName);
void LaunchExe(string szExe, string szArg);
}
public class RIL
{
// Fields
private COSecRILProxy m_CoClass;
private ISecProxyRILInterface m_CoInterface;
private static RIL m_single;
// Methods
static RIL();
private RIL();
public static void AddCallForwardingSettings(uint dwReason, uint dwInfoClass, string wszAddress, uint dwDelayTime, out uint pdwResult);
public static void CallBlockerUpdateInfo(string pwszUpdatedUserInfo, uint dwOpMode, out uint dwResult);
public static ISecProxyRILInterface CallInterface();
public static void GetAudioMute(out uint dwEnable);
public static void GetCallBarringStatus(uint dwType, uint dwInfoClass, string szPassword, out uint pdwBarringStatus, out uint pdwResult);
public static void GetCallForwardingSettings(uint dwReason, uint dwAddressID, out uint pdwStatus, out uint pdwNumType, out string pwszAddress, out uint pdwDelayTime, out uint pdwResult);
public static void GetCallWaitingStatus(out uint pdwInfoClass, out uint pdwResult);
public ISecProxyRILInterface GetComInterface();
public static void GetIMEI(out string IMEI);
public static void GetIMSI(out string IMSI);
public static RIL GetInstance();
public static void GetLockingStatus(uint m_dwLockFacility, out uint pdwLockStatus, out uint pdwResult);
public static void GetOperatorList(out byte[] info, out uint pdwCount, out uint pdwResult);
public void Initialize();
public static void PerformImeiCompare(out string strSalesCode, out uint dwResult, out string strErrorMessage);
public static void RemoveCallForwardingSettings(uint dwReason, uint dwInfoClass, out uint pdwResult);
public static void RIL_Devspecific2DWORD(uint dwCmdID, out uint pdwParam1, out uint pdwParam2, out uint pdwResult);
public static void SetAudioMute(uint dwEnable);
public static void SetCallBarringStatus(uint dwType, uint dwInfoClass, string szPassword, uint dwBarringStatus, out uint pdwResult);
public static void SetCallWaitingStatus(uint dwInfoClass, uint dwStatus, out uint pdwResult);
public static void SetCurrentOperator(uint dwMode, IntPtr info, out uint pdwResult);
}
public class RilCBMsgConfig
{
// Fields
public uint cbSize;
public List<RILRANGE> channelList;
public uint dwBroadcastMsgLangs;
public uint dwParams;
public bool fAccept;
// Methods
public RilCBMsgConfig();
public void AddChannel(RILRANGE range);
public bool Contains(RILRANGE range);
public uint GetCbSize();
public RILCBMSGCONFIG GetConfigStruct();
public static RILRANGE GetRange(int channel);
public static byte[] MakeRawData(RilCBMsgConfig cbConfg);
public static RilCBMsgConfig ParseData(uint total, uint size, byte[] rawData);
public override string ToString();
// Nested Types
[StructLayout(LayoutKind.Sequential)]
public struct RILCBMSGCONFIG
{
public uint cbSize;
public uint dwParams;
public uint dwBroadcastMsgLangs;
public bool fAccept;
[MarshalAs(UnmanagedType.ByValArray, SizeConst=1)]
public byte[] channelList;
}
[StructLayout(LayoutKind.Sequential)]
public struct RILRANGE
{
public uint dwMin;
public uint dwMax;
}
}
[StructLayout(LayoutKind.Sequential)]
public struct RILOPERATORNAMES
{
public uint cbSize;
public uint dwParams;
public string szLongName;
public string szShortName;
public string szNumName;
public string szCountryCode;
}
public class Sys
{
// Fields
private COSecSYSProxy m_CoClass;
private ISecProxySYSInterface m_CoInterface;
private static Sys m_single;
// Methods
static Sys();
private Sys();
public static ISecProxySYSInterface CallInterface();
public ISecProxySYSInterface GetComInterface();
public static Sys GetInstance();
public void Initialize();
}
public class Win32
{
// Fields
public static uint CREATE_ALWAYS;
public static uint CREATE_NEW;
public static uint FILE_ATTRIBUTE_ARCHIVE;
public static uint FILE_ATTRIBUTE_COMPRESSED;
public static uint FILE_ATTRIBUTE_DIRECTORY;
public static uint FILE_ATTRIBUTE_ENCRYPTED;
public static uint FILE_ATTRIBUTE_HIDDEN;
public static uint FILE_ATTRIBUTE_INROM;
public static uint FILE_ATTRIBUTE_NORMAL;
public static uint FILE_ATTRIBUTE_NOT_CONTENT_INDEXED;
public static uint FILE_ATTRIBUTE_OFFLINE;
public static uint FILE_ATTRIBUTE_READONLY;
public static uint FILE_ATTRIBUTE_REPARSE_POINT;
public static uint FILE_ATTRIBUTE_ROMMODULE;
public static uint FILE_ATTRIBUTE_ROMSTATICREF;
public static uint FILE_ATTRIBUTE_SPARSE_FILE;
public static uint FILE_ATTRIBUTE_SYSTEM;
public static uint FILE_ATTRIBUTE_TEMPORARY;
public static uint FILE_FLAG_BACKUP_SEMANTICS;
public static uint FILE_FLAG_DELETE_ON_CLOSE;
public static uint FILE_FLAG_NO_BUFFERING;
public static uint FILE_FLAG_OVERLAPPED;
public static uint FILE_FLAG_POSIX_SEMANTICS;
public static uint FILE_FLAG_RANDOM_ACCESS;
public static uint FILE_FLAG_SEQUENTIAL_SCAN;
public static uint FILE_FLAG_WRITE_THROUGH;
public static uint FILE_SHARE_DELETE;
public static uint FILE_SHARE_READ;
public static uint FILE_SHARE_WRITE;
public static uint GENERIC_ALL;
public static uint GENERIC_EXECUTE;
public static uint GENERIC_READ;
public static uint GENERIC_WRITE;
public static uint HKEY_CLASSES_ROOT;
public static uint HKEY_CURRENT_USER;
public static uint HKEY_LOCAL_MACHINE;
public static uint HKEY_USERS;
private COSecWin32Proxy m_CoClass;
private ISecProxyWin32Interface m_CoInterface;
private static Win32 m_single;
public static uint MODULE_ATTR_NODEBUG;
public static uint MODULE_ATTR_NOT_TRUSTED;
public static uint OPEN_ALWAYS;
public static uint OPEN_EXISTING;
public static uint OPEN_FOR_LOADER;
public static string REG_WM_BUSY_FLAG;
public static string REG_WM_GPRS_ALWAYSON;
public static string REG_WM_GPRS_APN;
public static string REG_WM_GPRS_AUTH_TYPE;
public static string REG_WM_GPRS_NAME;
public static string REG_WM_GPRS_PASSWORD;
public static string REG_WM_GPRS_PROFILES_TO_DELETE;
public static string REG_WM_GPRS_UNAME;
public static string REG_WM_MMS_APN;
public static string REG_WM_MMS_MMSC;
public static string REG_WM_MMS_MSGSIZE;
public static string REG_WM_MMS_NAME;
public static string REG_WM_MMS_PROFILES_TO_DELETE;
public static string REG_WM_MMS_PROXY;
public static string REG_WM_PROXY_ADDR;
public static string REG_WM_PROXY_APN;
public static string REG_WM_PROXY_DOMAIN;
public static string REG_WM_PROXY_NAME;
public static string REG_WM_PROXY_PORT;
public static string REG_WM_PROXY_PROFILES_TO_DELETE;
public static string REG_WM_ROOT;
public static uint TRUNCATE_EXISTING;
// Methods
static Win32();
private Win32();
public static ISecProxyWin32Interface CallInterface();
public static void CloseHandle(uint hObject);
public static void CopyFile(string lpExistingFileName, string lpNewFileName, int bFailIfExists);
public static void CreateFile(string lpFileName, uint dwDesiredAccess, uint dwShareMode, uint dwCreationDisposition, uint dwFlagsAndAttributes, out uint phCreateFile);
public static void DeleteFile(string lpFileName);
public ISecProxyWin32Interface GetComInterface();
public static void GetFileSize(uint hFile, out uint lpFileSizeHigh);
public static Win32 GetInstance();
public void Initialize();
public static void LaunchExe(string szExe, string szArg);
public static void ReadFile(uint hFile, out byte[] lpBuffer, uint nNumberOfBytesToRead, out uint lpNumberOfBytesRead);
public static void RegistryGetDWORD(uint HKEY, string pwszPath, string valueName, out uint value);
public static void RegistryGetString(uint HKEY, string pwszPath, string valueName, out string value);
public static void RegistrySetDWORD(uint HKEY, string pwszPath, string valueName, uint value);
public static void RegistrySetString(uint HKEY, string pwszPath, string valueName, string value);
public static void WriteFile(uint hFile, byte[] lpBuffer, uint nNumberOfBytesToWrite, out uint lpNumberOfBytesWritten);
}
}
It seems the API I need to make DiagProvXML work is still there. I might give it an update to support the Focus S (also Focus W & co.)
Ill need somebody with a Focus S to test it for me also.
Click to expand...
Click to collapse
I can test it but which one of the codes in the opening post is done correctly?
@Marvin_S: If you do a search you can find my post from a couple weeks back with various tests for the Samsung gen2 DLLs. They are indeed different from the gen1 DLLs, but offer a lot of exciting new capabilities. Unfortunately, there's also some kind of check or block on third-party use of the DLLs. I'm not yet sure exactly what caused it to not work. I'm still working on that, though.
EDIT: You've been able to make that work? My test app either produced an error message (file not found, of all things) or simply crashed each time I tried to use one of those APIs.
GoodDayToDie said:
@Marvin_S: If you do a search you can find my post from a couple weeks back with various tests for the Samsung gen2 DLLs. They are indeed different from the gen1 DLLs, but offer a lot of exciting new capabilities. Unfortunately, there's also some kind of check or block on third-party use of the DLLs. I'm not yet sure exactly what caused it to not work. I'm still working on that, though.
EDIT: You've been able to make that work? My test app either produced an error message (file not found, of all things) or simply crashed each time I tried to use one of those APIs.
Click to expand...
Click to collapse
No, untested, just inspected the samsung xap. I already assumed it would not work, but I posted it here for future reference for myself.
Ah too bad, can you call any api at all? For example the launchexe? it seems like they renamed rapiconfig.exe into ConfigXML.exe (or maybe rapiconfig is still there) it seems that ConfigXML.exe does not accept raw xml indeed but rather canned commands.
I included the source for the app, so feel free to take a look (and read the thread of tester comments, since I don't have a suitable device for testing).
Registry access: failed.
Filesystem access (yes the new DLLs seem to offer it): failed.
Provxml: failed
Other, trivial things: failed.
The OEM apps all contain a file simply called "_" which is a simple text file containing hex data as a string. I suspect the problems may be related to this file. If it's some kind of signature, that's going to be very hard to fake.
Here is the test app and source
[XAP][SOURCE][MANGO] Samsung gen2 interop test app v2
Any news from anyone?

Galaxy S3 ver 4.1.1 - Trying to start Activity from Emergency Dialer after placeCall

We are working with a Galaxy S3 (Android 4.1.1). We are able to get the activity from param.thisObject and change the title by getting the activity and calling setTitle(), but when we want to start a new activity, the activity doesn't start. Does anyone know how to spawn a new activity?
Our code is building off of SmileyClock in the tutorial.
Main.java
---------------------------------------------------------------------------------------------------------------------------------------------------------------
package com.example.SmileyClock;
import static de.robv.android.xposed.XposedHelpers.findAndHookMethod;
import android.aMain.javapp.Activity;
import android.content.Intent;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
import de.robv.android.xposed.IXposedHookLoadPackage;
import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XSharedPreferences;
import de.robv.android.xposed.XposedBridge;
import de.robv.android.xposed.callbacks.XC_LoadPackage.LoadPackageParam;
public class Main implements IXposedHookLoadPackage {
@override
public void handleLoadPackage(LoadPackageParam lpparam) throws Throwable {
// TODO Auto-generated method stub
if (!lpparam.packageName.equals("com.android.phone"))//check if the package being loaded is systemUI
return;
//All code here is only called if it is indeed SystemUI
findAndHookMethod("com.android.phone.EmergencyDialer", lpparam.classLoader, "placeCall", new XC_MethodHook() {
@override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
Activity emergencyDialer = (Activity) param.thisObject;
emergencyDialer.setTitle("Title has been changed!");
Intent newIntent = new Intent(emergencyDialer, BlackScreenActivity.class);
newIntent.addFlgags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
emergencyDialer.startActivity(newIntent);
Activity emergencyDialer = (Activity) param.thisObject;
Object[] args = param.args;
View view = (View) args[0];
emergencyDialer.setTitle("" + view.getId());
Intent newIntent = new Intent(Intent.ACTION_VIEW, null, emergencyDialer, BlackScreenActivity.class);
emergencyDialer.startActivity(newIntent);
}
});
}
}
BlackScreenActivity.java
---------------------------------------------------------------------------------------------------------------------------------------------------------------
package com.example.SmileyClock;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.Window;
import android.view.WindowManager;
public class BlackScreenActivity extends Activity {
@override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_black_screen);
//Remove title bar
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
//Remove notification bar
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
//set content view AFTER ABOVE sequence (to avoid crash)
this.setContentView(R.layout.activity_black_screen);
try {
Thread.sleep(3000);
finish();
Log.v("Xposed", "Sleep is done");
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Log.v("ERROR CATCH THING", e.toString());
}
}
@override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.black_screen, menu);
return true;
}
@override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}

Getting java.lang.NoSuchFieldError with getXXXField

Hi,
I have hooked into afterHookedMethod to read some fields from an object but I'm getting java.lang.NoSuchFieldError and I don't understand why.
Say I have these files:
Code:
package com.android.demo;
public class Bar {
public boolean mBoolean;
public Bar() {
mBoolean = false;
}
}
Code:
package com.android.sample;
public class Foo {
Bar getBar() {
Bar bar = new Bar();
bar.mBoolean = true;
return bar;
}
}
And my Xposed hook:
Code:
findAndHookMethod(
"com.android.sample",
lpparam.classLoader,
"getBar",
new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
// This is supposed to be `bar`, right?
Object result = param.getResult();
// Throws java.lang.NoSuchFieldError: com.android.demo.Bar#mBoolean
Log.d(TAG, "mBoolean: " + String.valueOf(getBooleanField(result, "mBoolean")));
// In the end this is what I'm trying to do...
//setBooleanField(result, "mBoolean", false);
//Log.d(TAG, "mBoolean: " + String.valueOf(getBooleanField(result, "mBoolean")));
//param.setResult(result);
}
}
);
One thing that I should mention is that the real code I'm trying to change is obfuscated with Proguard. But I decoded it and looked for the method name - which was just "f" and use that instead of "getBar". I know I got the method name right because the error outputs the package name and class name correctly for the result object which is not obfuscated. And I'm sure this object has many public fields, but I can't access (or change for that matter) any of them without an exception being thrown.
What am I missing?
Whenever I've used this method, the first parameter has been the instance of the class (param.thisObject). I'm curious to know if it's possible to make it work the way you're trying to do with param.getResult().
But if you hook the constructor of the Bar class and try getObjectField with (param.thisObject, mBoolean) it should work.
PunchUp said:
Whenever I've used this method, the first parameter has been the instance of the class (param.thisObject). I'm curious to know if it's possible to make it work the way you're trying to do with param.getResult().
But if you hook the constructor of the Bar class and try getObjectField with (param.thisObject, mBoolean) it should work.
Click to expand...
Click to collapse
Maybe, but I'm not sure that allows me to achieve my end goal...
To be more specific, I'm trying to change the result of this:
https://github.com/android/platform...rc/com/android/email/SecurityPolicy.java#L120
Tried something simpler:
Code:
findAndHookMethod(
"com.android.emailcommon.provider.Policy",
lpparam.classLoader,
"a",
"android.database.Cursor",
new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
Log.d(TAG, "mPasswordMode = " +
String.valueOf(XposedHelpers.getIntField(param.thisObject, "mPasswordMode")));
}
}
);
Got this:
Code:
06-28 21:45:11.133 7201-7824/? E/Xposed: java.lang.NoSuchFieldError: com.android.emailcommon.provider.Policy#mPasswordMode
I don't understand what I'm missing...
I feel like an idiot...
I've been focusing on the methods and the fact that they are obfuscated that I forgot that the instance variables also are obfuscated.
It makes perfect sense now why none of this was working... Back to the drawing board.
Great Your question made me learn something new
PunchUp said:
Great Your question made me learn something new
Click to expand...
Click to collapse
Cool But what was that?
Save​

Reducing module memory footprint

Hello fellow devs
It's a well known fact that all modules are loaded into all processes, even if they have nothing to do with them, which makes a pretty big difference if you have ~20 modules active and ~30 processes running.
Would something like this prevent the situation from happening?
Code:
public final class XposedInit implements IXposedHookLoadPackage
{
// Only one field and one method which means small memory footprint?
private IXposedHookLoadPackage mainModule = null;
@Override
public final void handleLoadPackage(final LoadPackageParam lpp) throws Throwable
{
// Hardcode the packages we really use
if (lpp.packageName.equals("android") || lpp.packageName.equals(getClass().getPackage().getName()))
{
// Initialize the real part of the module only if it's really going to be used
if (mainModule == null) mainModule = new MyMainGrandModule();
mainModule.handleLoadPackage(lpp);
}
}
}
Any insight appreciated.

Casting and reflection issues in a method argument. okhttp3.OkHttpClient$Builder;->addInterceptor(···)

Hi guys, I'm trying to hook the constructor of
Java:
okhttp3.OkHttpClient$Builder
in order to add an interceptor that converts any OkHttp call into a curl call and log it (see https://github.com/mrmike/Ok2Curl by MrMike). But I'm having problems with reflection, say I must haven't understood it pretty well...
The idea is to call
Java:
.addInterceptor(okhttp3.Interceptor)
method JUST after the
Java:
OkHttpClient$Builder
instance has been constructed, but it's more painful than expected. (See code and code comments for further details)
Java:
@Override
public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lpparam) throws Throwable {
Class builderClass = XposedHelpers.findClassIfExists("okhttp3.OkHttpClient$Builder", lpparam.classLoader);
if(builderClass != null){
XposedBridge.hookAllConstructors(builderClass, new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
CurlInterceptor interceptor = new CurlInterceptor(new Loggable() {
@Override
public void log(String message) {
Log.v("Ok2Curl", message);
}
});
/*
Attempt nº1:
Cannot do it this way, it throws an exception because there's not (and there's actually not) a method
'okhttp3.OkHttpClient$Builder#addInterceptor(CurlInterceptor)' since CurlInterceptor is from the Ok2Curl library.
Maybe the '.callMethod()' cannot make implicit casting?
*/
Object attempt1 = XposedHelpers.callMethod(param.thisObject, "addInterceptor", interceptor);
/*
Attempt nº2:
Declaring explicitly the argument classes that addInterceptor(···) has, does not help.
I get an exception: it could not find an ".addInterceptor(java.lang.Class, ...CurlInterceptor)" method, so
this means Interceptor.class was taken as one of the method arguments and not as an argument type.
Anyways, given the results from attempt 1, it seems that .callMethod() will not do implicit casting whatsoever...
*/
Object attempt2 = XposedHelpers.callMethod(param.thisObject, "addInterceptor", Interceptor.class, interceptor);
/*
Attempt nº3:
Explicit casting from CurlInterceptor to okhttp3.Interceptor did not help...
java.lang.NoSuchMethodError: okhttp3.OkHttpClient$Builder#addInterceptor(com.moczul.ok2curl.CurlInterceptor)#bestmatch
*/
Object attempt3 = XposedHelpers.callMethod(param.thisObject, "addInterceptor", (okhttp3.Interceptor) interceptor);
}
});
}
}
Thanks in advance!

Categories

Resources