|
Yeah, took me about 15 minutes before I realized I was reading the same row over and over... (cheeky bastard)
|
|
|
|
|
Have a look at OpenSSL. It supports AES and you should be able to use if from Java and C. If you have problems using it from C then feel free to ask questions about how to use it. I believe there's a JNI wrapper for it as well to save you rolling your own but I've never used it.
Oh, and if you do a search for "Gladman" and "AES" you might find another open source implementation of AES. I've never used it but one of my co-workers does in a product. It's lighter weight than OpenSSL and you should be able to compile and link it with your C code.
Cheers,
Ash
|
|
|
|
|
Murugan k wrote: I need to encrypt the plan text using AES algorithm in java and decrypt the encrypted text using C.Any please give solution ASAP.
do you know how to write AES alogorithm in C and Java
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
Have a look at Brian Gladman's implementation. That shows you in balls-aching detail how to implement AES. If I were you I'd just use his or the one in OpenSSL.
Cheers,
Ash
|
|
|
|
|
Hi
I am using CClientDc in OnTimer().
Sample Code:
OnTimer()
{
CClientDc dc;
DisplayAll(dc,xCor,Ycor);
Release(&dc);
}
But When run the program through the Deleaker
I am getting GDI leak in this part. I am not sure weather the CClientDc is released. Also my applicatin size increases continously. Pls help to resolve this problem.
|
|
|
|
|
You do not have to call Release .
The destructor of CClientDC will do that when it goes out of scope.
The leak is probably because of something that is happening inside the DisplayAll function.
|
|
|
|
|
«_Superman_» is correct: First lose the Release and see if commenting out DisplayAll stops the leaks. If it does one sledgehammer approach is comment bits of the function out bit by bit until you find the problem.
Steve
|
|
|
|
|
Get rid of all drawing code in your OnTimer. Make sure OnPaint does all the
drawing correctly and then replace all the code in OnTimer with:
Invalidate();
That'll help sort out whether the problem is with the drawing code or whether you're committing another faux pas.
In case you're wondering Invalidate tells Windows that the window you've called it on needs repainting and it should send a WM_PAINT to the app when the message queue is otherwise empty. This WM_PAINT causes OnPaint to be called.
Cheers,
Ash
|
|
|
|
|
Hi All
How can i open Ms PowerPoint password protected file through code?I know password but i haven't idea how to open through code.
Please help me
|
|
|
|
|
|
Hi!
Could you help me please...
I need to save data to file from here:
for (DWORD x = 0; x < pNotification->Count; x++)
{
ASSERT(pNotification->aData[x].Type == JOB_NOTIFY_TYPE);
CJobInfo *pJobInfo = NULL;
if (! m_mapJobInfo.Lookup(pNotification->aData[x].Id, pJobInfo))
{
pJobInfo = new CJobInfo(pNotification->aData[x].Id);
m_mapJobInfo.SetAt(pNotification->aData[x].Id, pJobInfo);
}
ASSERT(pJobInfo != NULL);
pJobInfo->UpdateInfo(&pNotification->aData[x]);
::PostMessage(m_ThreadInfo.GetHwnd(), UDM_UPDATE_JOB_LIST, 0, 0);
}
This is a code of Print monitoring program. Thank you!
|
|
|
|
|
You need to add :
pJobInfo->SaveDataToFile();
After the UpdateInfo() call.
|
|
|
|
|
Rick York wrote: pJobInfo->SaveDataToFile();
nice onE!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
Hello,
Let me first start by telling you I have very little (read: none, ive read some parts in an ebook but..) experience with c++.
I'm trying to manage a callback to a more 'trusted' managed environment.
I'm trying to use SetWindowsHookEx(WH_CBT) on a specified application to monitor and alter window behavior.
I've created the HookProc in unmanaged c++ (see below) together with a Initialize function that takes as argument void* so I can call the function inside my managed application.
I pass the function of my managed application with Managed.getFunctionPointerforDelegate().
This seems to work.
However. If I hook the external process. (Read: Inject all of its threads seperately) it doesn't seem todo the callback to my managed application.
Winapi Override shows my unmanaged dll as being linked. (If I however can't find it through System.Diagnostics.Process.Modules)
The code:
The unmanaged part:
<FONT COLOR="#000099">#include "Hook.h"
</FONT><FONT COLOR="#999999">
</FONT><FONT COLOR="#FF6633">int</FONT><FONT COLOR="#663300"> (*</FONT>pfnCallback<FONT COLOR="#663300">) (</FONT><FONT COLOR="#FF6633">void</FONT><FONT COLOR="#663300">);</FONT><FONT COLOR="#FF6633">
void</FONT> Initialize<FONT COLOR="#663300">(</FONT>HANDLE retFunc<FONT COLOR="#663300">)
{</FONT><FONT COLOR="#FF0000">
if</FONT><FONT COLOR="#663300"> (</FONT>retFunc<FONT COLOR="#663300"> !=</FONT> INVALID_HANDLE_VALUE<FONT COLOR="#663300">)
{</FONT>
pfnCallback<FONT COLOR="#663300"> = (</FONT><FONT COLOR="#FF6633">int</FONT><FONT COLOR="#663300"> (</FONT>_cdecl<FONT COLOR="#663300"> *) (</FONT><FONT COLOR="#FF6633">void</FONT><FONT COLOR="#663300">))</FONT> retFunc<FONT COLOR="#663300">;</FONT><FONT COLOR="#FF6633">
int</FONT> a<FONT COLOR="#663300"> =</FONT> ThrowMessage<FONT COLOR="#663300">();</FONT><FONT COLOR="#FF0000">
if</FONT><FONT COLOR="#663300"> (</FONT>a<FONT COLOR="#663300">==</FONT><FONT COLOR="#999900">5</FONT><FONT COLOR="#663300">)
{</FONT>
ThrowMessage<FONT COLOR="#663300">();
}</FONT>
ThrowMessage<FONT COLOR="#663300">();
}
}</FONT><FONT COLOR="#FF6633">
int</FONT> ThrowMessage<FONT COLOR="#663300">()
{</FONT><FONT COLOR="#999999">
</FONT><FONT COLOR="#FF0000"> return</FONT><FONT COLOR="#663300"> (*</FONT>pfnCallback<FONT COLOR="#663300">)();
}</FONT><FONT COLOR="#FF6633">
int</FONT> HookProc<FONT COLOR="#663300">(</FONT><FONT COLOR="#FF6633">int</FONT> nCode<FONT COLOR="#663300">,</FONT> WPARAM wParam<FONT COLOR="#663300">,</FONT> LPARAM lParam<FONT COLOR="#663300">)
{</FONT>
ThrowMessage<FONT COLOR="#663300">();</FONT><FONT COLOR="#FF0000">
return</FONT> CallNextHookEx<FONT COLOR="#663300">(</FONT>NULL<FONT COLOR="#663300">,</FONT>nCode<FONT COLOR="#663300">,</FONT>wParam<FONT COLOR="#663300">,</FONT>lParam<FONT COLOR="#663300">);
}</FONT>
The c# part:
<FONT COLOR="#990000"> public class</FONT> HookManager<FONT COLOR="#663300">
{</FONT><FONT COLOR="#990000">
private</FONT> GCHandle gch<FONT COLOR="#663300">;</FONT><FONT COLOR="#999999">
</FONT><FONT COLOR="#990000"> private</FONT> delegate<FONT COLOR="#FF6633"> int</FONT> HookProc<FONT COLOR="#663300">();</FONT><FONT COLOR="#999999">
</FONT><FONT COLOR="#990000"> private static</FONT> HookProc hookProc<FONT COLOR="#663300">;</FONT><FONT COLOR="#999999">
</FONT><FONT COLOR="#990000">
private static</FONT> Stack<FONT COLOR="#663300"><</FONT>IntPtr<FONT COLOR="#663300">></FONT> hookList<FONT COLOR="#663300"> =</FONT><FONT COLOR="#990000"> new</FONT> Stack<FONT COLOR="#663300"><</FONT>IntPtr<FONT COLOR="#663300">>();</FONT><FONT COLOR="#990000">
public</FONT> HookManager<FONT COLOR="#663300">()
{</FONT>
hookProc<FONT COLOR="#663300"> =</FONT><FONT COLOR="#990000"> new</FONT> HookProc<FONT COLOR="#663300">(</FONT>HookEvent<FONT COLOR="#663300">);</FONT>
gch<FONT COLOR="#663300"> =</FONT> GCHandle<FONT COLOR="#663300">.</FONT>Alloc<FONT COLOR="#663300">(</FONT>hookProc<FONT COLOR="#663300">,</FONT> GCHandleType<FONT COLOR="#663300">.</FONT>Normal<FONT COLOR="#663300">);</FONT>
IntPtr managedReference<FONT COLOR="#663300"> =</FONT> Marshal<FONT COLOR="#663300">.</FONT>GetFunctionPointerForDelegate<FONT COLOR="#663300">(</FONT>hookProc<FONT COLOR="#663300">);</FONT>
Poseidon<FONT COLOR="#663300">.</FONT>Initialize<FONT COLOR="#663300">(</FONT>managedReference<FONT COLOR="#663300">);
}</FONT><FONT COLOR="#990000">
public</FONT><FONT COLOR="#FF6633"> void</FONT> HookIt<FONT COLOR="#663300">(</FONT>Process hook<FONT COLOR="#663300">)
{</FONT><FONT COLOR="#999999">
</FONT> IntPtr hModule<FONT COLOR="#663300"> =</FONT> Win32<FONT COLOR="#663300">.</FONT>GetModuleHandle<FONT COLOR="#663300">(</FONT><FONT COLOR="#009900">"Poseidon.dll"</FONT><FONT COLOR="#663300">);</FONT>
IntPtr ProcAddress<FONT COLOR="#663300"> =</FONT> Win32<FONT COLOR="#663300">.</FONT>GetProcAddress<FONT COLOR="#663300">(</FONT>hModule<FONT COLOR="#663300">,</FONT><FONT COLOR="#009900"> "HookProc"</FONT><FONT COLOR="#663300">);</FONT>
ProcessThread<FONT COLOR="#663300">[]</FONT> threads<FONT COLOR="#663300"> =</FONT><FONT COLOR="#990000"> new</FONT> ProcessThread<FONT COLOR="#663300">[</FONT>hook<FONT COLOR="#663300">.</FONT>Threads<FONT COLOR="#663300">.</FONT>Count<FONT COLOR="#663300">];</FONT>
hook<FONT COLOR="#663300">.</FONT>Threads<FONT COLOR="#663300">.</FONT>CopyTo<FONT COLOR="#663300">(</FONT>threads<FONT COLOR="#663300">,</FONT><FONT COLOR="#999900"> 0</FONT><FONT COLOR="#663300">);</FONT>
foreach<FONT COLOR="#663300"> (</FONT>ProcessThread thread in threads<FONT COLOR="#663300">)
{</FONT>
IntPtr HHOOK<FONT COLOR="#663300"> =</FONT> Win32<FONT COLOR="#663300">.</FONT>SetWindowsHookEx<FONT COLOR="#663300">(</FONT>Win32<FONT COLOR="#663300">.</FONT>HookType<FONT COLOR="#663300">.</FONT>WH_CBT<FONT COLOR="#663300">,</FONT> ProcAddress<FONT COLOR="#663300">,</FONT> hModule<FONT COLOR="#663300">, (</FONT>uint<FONT COLOR="#663300">)</FONT>thread<FONT COLOR="#663300">.</FONT>Id<FONT COLOR="#663300">);</FONT>
Console<FONT COLOR="#663300">.</FONT>WriteLine<FONT COLOR="#663300">(</FONT><FONT COLOR="#009900">"{0}, {1}, {2}"</FONT><FONT COLOR="#663300">,</FONT> hModule<FONT COLOR="#663300">,</FONT> ProcAddress<FONT COLOR="#663300">,</FONT> HHOOK<FONT COLOR="#663300">);</FONT>
hookList<FONT COLOR="#663300">.</FONT>Push<FONT COLOR="#663300">(</FONT>HHOOK<FONT COLOR="#663300">);
}
}</FONT><FONT COLOR="#990000">
public</FONT><FONT COLOR="#FF6633"> int</FONT> HookEvent<FONT COLOR="#663300">()
{</FONT>
Console<FONT COLOR="#663300">.</FONT>WriteLine<FONT COLOR="#663300">(</FONT><FONT COLOR="#009900">"Hookevent called!"</FONT><FONT COLOR="#663300">);</FONT><FONT COLOR="#FF0000">
return</FONT><FONT COLOR="#999900"> 5</FONT><FONT COLOR="#663300">;
}</FONT><FONT COLOR="#990000">
private static class</FONT> Poseidon<FONT COLOR="#663300">
{
[</FONT>DllImport<FONT COLOR="#663300">(</FONT><FONT COLOR="#009900">"Poseidon.dll"</FONT><FONT COLOR="#663300">)]</FONT><FONT COLOR="#990000">
public static extern</FONT><FONT COLOR="#FF6633"> void</FONT> Initialize<FONT COLOR="#663300">(</FONT>IntPtr callback<FONT COLOR="#663300">);
}
}</FONT>
Thanks already for reading this far. Does anyone have any idea this is ? Or suggestions?
I desperately try to get this to work. It's driving me nuts right now.
|
|
|
|
|
AlmightyEdge wrote: I've created the HookProc in unmanaged c++ (see below) together with a Initialize function that takes as argument void* so I can call the function inside my managed application.
[EDIT]Why do you need to work around?In case it's not global hook you could use it directly from your .NET app but if it is you can't do it it using managed code[/EDIT]
I believe that this article is exactly for you.
Life is a stage and we are all actors!
modified on Wednesday, June 16, 2010 5:21 PM
|
|
|
|
|
I thought that, in order to hook an external thread you needed to use unmanaged code .
Thanks alot for the example, looks promising. I will try it out tomorrow .
|
|
|
|
|
Unfortunately it doesn't seem to work for external threads
|
|
|
|
|
This whole area is a tricky subject. For starters the hook procedure for WH_CBT hooks that run in other processes must be in a DLL (which is injected into all the processes being hooked). Since you're trying to call a managed function from this DLL in the context of every hooked process, the managed code must also (somehow) be injected along with the DLL that contains the hook procedure. This could lead to a common problem which can occur when trying to build component systems using .NET: trying to load multiple versions of the CLR into a single process. See In-Process Side-by-Side[^] for details on this.
Perhaps you'd be better using some kind of IPC instead of a direct function call.
Steve
|
|
|
|
|
I thought a direct function call would be the fastest.
You got any suggestion for IPC?
|
|
|
|
|
A direct function call would be the fastest, but direct function calls can only occur within a process. Since you're hooking other processes this could cause problems.
Steve
|
|
|
|
|
I need to create a dll that will wrap Microsoft wininet.dll
The idea is to install this Dll instead of the regular one in all the organization workstation and add some adjustments to few actions in the wininet.dll, especially logs
Is it possible? I need to do it so the application that use the wininet.dll wont be noticed the different.
|
|
|
|
|
alto wrote: I need to create a dll that will wrap Microsoft wininet.dll
The idea is to install this Dll instead of the regular one in all the organization workstation and add some adjustments to few actions in the wininet.dll, especially logs
Is it possible? I need to do it so the application that use the wininet.dll wont be noticed the different
little difficult task but achievable! you need to program all the function exposed by WinInet with same order and need to deploy it over wininet!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
Probably a bad idea... thinking about how many legal scenarios there are to change wininet.dll.
|
|
|
|
|
Fat file system store file create date in 2 bytes. Same way it stores file create time in 2 bytes.
Is there any function which tells whether this 2 bytes date/time is valid or not?
|
|
|
|
|
Provided you have the reference documentation, I suppose you (or we) may possibly write it.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|