Debugging a dll - Windows Mobile Development and Hacking General

I'm creating a project as a dll. Can anybody tell me how to go about debugging it. I attach it to the remote process "services.exe" but any breakpoints I put, dont hit and display an exclamation mark, saying that no executable code exists at that point..
How do you guys debug ur DLLs??

be sure that services.exe is the correct process
bye

Let me explain a bit. Actually I'm trying to write a WinMob service (This is my first time writing a service dll, infact, first time writing a dll).
I created a dll with the DLL_PROCESS_ATTACH case in the ul_reason_for_call calling a SPC_init function (exported using __declspec(dllexport)).
Moreover, I added these entries to the registry:
[HKEY_LOCAL_MACHINE\Services\ShantzABC]
"Order"=dword:00000009
"Index"=dword:00000000
"Prefix"="SPC"
"Keep"=dword:00000001
"Dll"="ShantzABC.dll"
"FriendlyName"="ShantzABC"
But the service didn't load. Then I added the line "services load ShantzABC" to the deployment options of my VS2005 project. Now, on pressing F5, the service loads (I know because I put a MessageBox() inside the SPC_init, which is now displayed on screen) BUT:
1. I can't see the ShantzABC.dll loaded in Remote Process Viewer tool (seeing for services.exe)
2. Moreover, I can't hit any breakpoints in my project, even the one kept on the MessageBox() line. (Though now they have stopped giving the error "not an executable line" that they were giving earlier)
Actually I'm trying to start a project which could benefit greatly if it was a service instead of me writing an exe for it..
So, any pointers??
EDIT: added a part of the code:
Code:
#include "stdafx.h"
#include "ShantzABC.h"
#include <windows.h>
#include <commctrl.h>
HINSTANCE g_hInst;
// This is an example of an exported function.
__declspec(dllexport) HRESULT SPC_init(void)
{
HRESULT result;
MessageBox(NULL, TEXT("initCtrl"), TEXT("INIT"), MB_OK);
result = S_OK;
return result;
}
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
HRESULT result;
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
//save instance handle
g_hInst = (HINSTANCE) hModule;
result = SPC_init();
MessageBox(NULL, TEXT("initCtrl"), TEXT("main"), MB_OK);
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}

1. implements all the exported functions for service:
Init, Open, Close, Deinit, IOControl, Read, Seek, Write also if empty (just return 0)
2. instead to use F5 to debug it, try to deploy the dll and attach the process to debug it: Debug > Attach to process.... (vs2005's menu)
i hope this help you

Could you please direct me to an SW development environment, which documents the above functions, Reg_Key meanings etc. sort of a reference guide? What compilers/linkers do you guys use ?

crino said:
1. implements all the exported functions for service:
Init, Open, Close, Deinit, IOControl, Read, Seek, Write also if empty (just return 0)
2. instead to use F5 to debug it, try to deploy the dll and attach the process to debug it: Debug > Attach to process.... (vs2005's menu)
Click to expand...
Click to collapse
I implemented all the functions and just returned 1. (didnt return 0 because read on a msdn blog that returning 0 form dllmain or xxx_Init will unload the dll)
But again on attaching to services.exe, its not loading my dll(or unloads it soon after loading). (Dll is kept in \windows)
So, cant find the dll in the modules window and so cant load the symbols for it in order to debug it..

Related

RIL_GetEquipmentInfo Problems

Trying to understand RIL and how to pass all the handles and various parameters. In my code i try to initialize RIL and then use the RIL_GetEquipmentInfo function to try and get some results from it. However when i try my application out , i get something like each time i press the command button ....
406
408
40B
411
....
it seems to increment and i thought i was ment to get something like HIMALAYAS back ... Where am i wrong ???
*********************************************
bool CTerminalDlg::RIL_Initialize(DWORD dwIndex)
{
TCHAR szString[256];
CEdit* pEditShow = (CEdit*)GetDlgItem(IDC_EDIT3);
result = ::RIL_Initialize(1, OnResultCallback, OnNotifyCallback, dwNotificationClasses, g_dwParam, &g_hRil);
HRESULT test = RIL_GetEquipmentInfo(g_hRil);
::wsprintf(szString, L" %X", test);
pEditShow->SetWindowText(szString);
return g_hRil != NULL;
}
the result is returned asyncronously via the OnResultCallback function.
alright i get ya ......... so that means the answer i should get ( HTC ) will be passed to a parameter inside the OnResultCallback function ? How would i display it in a message box though ?
thanks for your help i'm struggling here.
1)http://forum.xda-developers.com/viewtopic.php?t=28835
2)there is bad idea to show message box from callback
i think this callback execute in internal RIL thread
get data that you needed from RILEQUIPMENTINFO struct and put to temp buffer
show data from temp buffer in your main thread
for example:
in main thread
1)reset Event
2)call Ril_GetEquipmentInfo
3)wait Event
4)show MessgeBox
in callback
1)store data from RILEQUIPMENTINFO to temp buffer
2)set Event
3)return

Win32 Mode Failure to set text in static control

I have a problem in setting controls in a Win32 application.
When I use SendMessage to set a text string in a static control I get error number 120 which translated means: "This function is only valid in Win32 mode."
Here's the background:
I'm using Visual Studio 2005, I've installed the Windows Mobile 5 SDK.
The project was created using the New Project Wizard, with the following settings:
Visual C++/Smart Device
Win32 Smart Device Project
Platform SDK is: Windows Mobile 5.0 Pocket PC SDK
Windows application
I've added a dialog template resource and can bring up a dialog based on that resource. It contains a static control that I can read the text from, but attempting to set the text gives me the above error.
The relevent code (within the WM_INITDIALOG message handler) is:
Code:
char buffer[100];
HWND hCtrl = ::GetDlgItem(hDlg, IDC_TITLE);
LRESULT result = ::SendMessage(hCtrl, WM_GETTEXT, (WPARAM)80, (LPARAM)buffer);
This works, I get the correct text (ie the text I have placed into the static control using the dialog template editor) copied into the buffer. What follows is:
Code:
buffer[0] = 'A'; // Just to set up a different string
result = ::SendMessage(hCtrl, WM_SETTEXT, (WPARAM)0, (LPARAM)buffer);
if (result == 0)
{
LPVOID lpMsgBuf;
DWORD error = ::GetLastError();
::FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, error, 0, (LPTSTR)&lpMsgBuf, 0, NULL);
::MessageBox(NULL, (LPCTSTR)lpMsgBuf, (LPCWSTR)"LError", MB_OK | MB_ICONINFORMATION);
::LocalFree(lpMsgBuf);
}
The attempt to set the changed text string fails (ie result == 0), and the last error is 120, which is translated to the error message above.
This works the same in both the Windows Mobile 5 emulator, and if I run it on my Atom.
What does this mean? How could it be anything other than Win32 mode?
Is there a function or something I have to call to put it into Win32 mode?
Or is it a project setting in VS2005 that I haven't been able to find?
I'd very much appreciate any help on this.
Peter
Your build target was a PPC 2003 variant for this project, correct? If so (and I'm assuming that it is so because you mention trying this on the PPC emulator), then you are most certainly not in Win32 mode, rather you are targeting WinCE. To target win32, you need to go into configuration manager and change your target at which point your program will no longer run on PPC.
More to your problem: I don't believe that you can dynamically change dialog static control properties through messaging on WinCE. I may be wrong on this here though too....

How to execute arbitrary code...

Dear all,
I want to publish here one very very simple method how you can execute arbitrary code in your applications.
This method can be used to protect your software with runtime decryption\encryption mechanisms.
For example, your license checking function can be stored in the exe-file somehow encrypted and you'll be able to decrypt it in runtime end execute.
Using this method you can even encrypt all your application and decrypt only necessary functions just before you want to execute them.
Of course you should understand that any security mechanisms sooner or later will be cracked, but our goal is not to create non-breakable security, but to make cracking process more expensive then buying a license.
So, the idea is simple: we can prepare some buffer in the application and in the runtime copy there code we want to execute.
Here is source code:
Code:
/*
After compilation it is necessary to change flags of .mysec
from 60000020 (Code Execute Read) на E0000020 (Code Execute Read Write)
Just open exe-file, search for 0x20 0x00 0x00 0x60 after text ".mysec"
and change it to 0x20 0x00 0x00 0xE0
*/
#include <windows.h>
// turn off optimiztions
#pragma optimize("", off)
// define our code segment
#pragma code_seg(".mysec")
// let's allocate some place in our new segment
__declspec(allocate(".mysec")) BYTE pBUF[100];
// put functions to the new segment (not necessary!)
int func1(int i)
{
return i*2;
}
int func2(void) // just fake function. we'll need it to find size of func1
{
return 5;
}
// turn on optimizations
#pragma optimize("", on)
// switch back to .text segment
#pragma code_seg()
// define pointer to function
typedef int (*pfn_t)(int i);
int _tmain(int argc, TCHAR* argv[])
{
func2(); // not so necessary, but linker might remove unused functions... :-\
// here we're copying code of func1 into the buffer :)
// in fact, here should be some procedure decrypting necessary
// code into our buffer, but to simplify the example, I'll
// just copy one of existing functions int the buffer
// and then execute it
memcpy(pBUF, &func1, (int)&func2 - (int)&func1);
int a = ((pfn_t)(void*)pBUF)(4); // execute
// show result
wchar_t pBuf[20] = {0};
wsprintf(pBuf, L"a = %d", a);
::MessageBoxW(0, pBuf, L"tst1", MB_OK);
return 0;
}
I'll also attach the compiled application for those who think it won't work.
Thank you!
Best regards,
efrost

Receiving error: Cannot convert from element type Object

Hello,
As the title states, I'm receiving an error that says "Cannot convert from element type Object to Bluetooth Device. The following is the highlighted code:
Code:
if (pairedDevices.size() > 0) {
findViewById(R.id.title_paired_devices).setVisibility(View.VISIBLE);//make title viewable
for (BluetoothDevice device : pairedDevices) {
mPairedDevicesArrayAdapter.add(device.getName() + "\n" + device.getAddress());
}
} else {
mPairedDevicesArrayAdapter.add("no devices paired");
}
I have a feeling it has something to do with java generics, but I'm not quite sure how to fix it. Would anyone be able to offer help?
Thanks
theBasher91 said:
Code:
for (BluetoothDevice device : pairedDevices)
Click to expand...
Click to collapse
Well I would suspect that pairedDevices is a list or array of type Object? Not sure as you dont post the actual error or line numbers... but cast within the for loop if this is the case
Code:
for (Object item : pairedDevices)
{
BluetoothDevice device = (BluetoothDevice) item;
}
Just a thought
Or, assuming that pairedDevices is an ArrayList or other type that implements the collections interface, you're best bet would be to ensure that it is parameterized correctly.
For example:
Code:
ArrayList<BluetoothDevice> = new ArrayList()<BluetoothDevice>

Help me translate this coding

I'm learning how to manage data that I pull from DB (MYSQL) from this coding. I tried to figure out from free source coding but got stuck on this function, can anybody explain to me flow of this coding?
Code:
protected void onPostExecute(Void aVoid) {
name = names.split(":");
email = emails.split(":");
phone = phones.split(":");
combinedArray = combinedText.split(":");
listView.setAdapter(new ArrayAdapter<String>(RetrieveData.this,
android.R.layout.simple_list_item_1, combinedArray));
progressDialog.dismiss();
}
and when I tried to use this code, red line prompt out and saying that cannot resolved this constructor on if i change
Code:
listItems
to
Code:
names
variables on this
Code:
adapter=new ArrayAdapter<String>(this,
R.layout.list_item, R.id.txtitem, listItems);
I don't understand why I need to use 'split' to pull out the output on listview.

Categories

Resources