Click here to Skip to main content
Click here to Skip to main content

Patch my Arabic Locale on Windows mobile

By , 6 May 2012
 
This is an old version of the currently published article.

Introduction

How to make device support for Unicode by hack InitLocale function inside coredll.dll entire the system not your application ,this way to set your Arabic Locale entire of System to be able Save Arabic on File . without this you you can't saving Arabic inside file or save note or appointment or calender

Note : we used this way to all device manufacture such as HTC ,ASUS ,InterMek ...etc since the device come without Arabic Locale

Background

Most of Application try to read some of information from Local ,By Function insided frame work or MFC ...etc ,what ever the language you used all Frame work should call InitLocal function inside coredll.dll ,so what you need actually in this case hook this function

Using the code

As we said before we have to obtain pointer for InitLocale Function inside coredll.dll and save it inside fpInitlocale to use it later we will talk more about that .

Also we need to CreateMutex ,BTW it's good to know what mutex meaning

CreateMutex :A mutex is a synchronization object that negotiates mutual exclusion among threads of a single process to avoid simultaneous modifications on common resources such as global variables.

  /* some shared stuff that has to go */
HINSTANCE hinstCore = (HINSTANCE)GetModuleHandle(L"COREDLL");
FARPROC fpInitLocale = GetProcAddress(hinstCore,L"InitLocale");
HANDLE _nlsMutex=CreateMutex(NULL,0,L"NLSMUTEX");
HANDLE _nlsHeap=CreateFileMapping(INVALID_HANDLE_VALUE,NULL,4,0,0x10000,L"NLSHEAP"); 

Now to share memory between process you have to use CreateFileForMapping to make your locale shared between all process

HANDLE hNLSFile, hNLSMap, hNLSOrig;
/* create the new mapping with slightly different name */
hNLSFile = CreateFileForMapping(nlsFile,GENERIC_READ,0,0,OPEN_EXISTING,0,0);
hNLSMap = CreateFileMapping(hNLSFile,0,PAGE_READONLY,0,0,L"some nice string longer that 7 chars"); 
FSMAP *nls = HandleToMap(hNLSMap);
/* get original */
hNLSOrig = CreateFileMapping(INVALID_HANDLE_VALUE,0,PAGE_READONLY,0,0,L"NLSFILE"); 
LPVOID origView=MapViewOfFile(hNLSOrig,6,0,0,0);
FSMAP *orig = HandleToMap(hNLSOrig); 

The trick of code here to rename the original Name ,(to make them invisible) ,because all of

  • NLSFILE
  • NLSMUTEEX
already cached inside running process.
orig->name->name[0]='_'; /* change the first letter */
/* rename our file mapping to be NLSFILE :)*/
wcscpy(nls->name->name, L"NLSFILE");
/* rename NLSHEAP - it is cached in all coredll instances (all apps) */
FSMAP *nlsHeap= HandleToMap(hNLSOrig);
nlsHeap->name->name[0]='_';
/* rename NLSMUTEX - all coredll expect it to be available. force recreation */
MUTEX *m = HandleToMutex(_nlsMutex);
m->name->name[0]='_';  

Now will go to All running Process and inject our NLSFILE and NLSMUTEX instead of original one 

PROCESSENTRY32 pe32;
HANDLE hSnap=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS | 0x40000000 /*TH32CS_SNAPNOHEAPS*/, NULL);
pe32.dwSize=sizeof(pe32);
BOOL bb=Process32First(hSnap,&pe32);
while (bb) {
/* all processes - including NK.EXE */
CallInProcess(pe32.th32ProcessID, fpInitLocale, NULL);
pe32.dwSize=sizeof(pe32);
bb=Process32Next(hSnap, &pe32);
}
CloseToolhelp32Snapshot(hSnap); 

Finally to use this code Add nls.cpp inside you process and call this function

PatchNLS("\windows\younls.nls"); 

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

emranallan
Software Developer (Senior)
Jordan Jordan
Member
Mobile Developer with deep Experience in Handheld Device Pocket Pc, Smart Phone in Win32, MFC With more than 8 years ago."Arabizer, Hook Function, Poom, Wirless Application, and low level Application". By C++ MFC and win32
 
http://windowsmobiledn.blog.com/

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

Discussions on this specific version of this article. Add your comments on how to improve this article here. These comments will not be visible on the final published version of this article.
 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
QuestionTitle, use of word "local", bit short.mvpOriginalGriff6 May '12 - 5:48 
AnswerRe: Title, use of word "local", bit short.memberemranallan6 May '12 - 6:23 
AnswerRe: Title, use of word "local", bit short.memberemranallan6 May '12 - 7:06 
QuestionFormattingmvpMehdi Gholam6 May '12 - 4:30 
AnswerRe: Formattingmemberemranallan6 May '12 - 4:35 
GeneralRe: FormattingmvpMehdi Gholam6 May '12 - 4:40 
GeneralRe: Formattingmemberemranallan6 May '12 - 4:56 
please check now Dear Mehdi
windowsmobiledn.blog.com

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   


Discussions posted for the Published version of this article. Posting a message here will take you to the publicly available article in order to continue your conversation in public.
 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
-- There are no messages in this forum --
Permalink | Advertise | Privacy | Mobile
Web02 | 2.6.130516.1 | Last Updated 6 May 2012
Article Copyright 2012 by emranallan
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid