Accueil > > > STACK WATCHER
STACK WATCHER
Information sur la source
Description
Permet la visualisation l'état de la pile, et donc des registres, d'un thread en cours d'execution. Toutes les explications sont ici ainsi qu'un petit rappel sur les registres : http://lilxam.blogspot.com/2008/02/stack-watcherre gisters-viewer.html
Source
- #include <windows.h>
- #include <cstdlib>
- #include <iostream>
- #include <tlhelp32.h>
-
- using namespace std;
-
- typedef HANDLE (__stdcall *PfOpenT)(DWORD, BOOL, DWORD);
- DWORD GetPIDByProcess(char argv[]);
- void SetDebugPrivilege();
-
- void SetDebugPrivilege(){
- TOKEN_PRIVILEGES privilege;
- LUID Luid;
- HANDLE handle1;
- HANDLE handle2;
- handle1 = OpenProcess(PROCESS_ALL_ACCESS, FALSE, GetCurrentProcessId());
- OpenProcessToken(handle1, TOKEN_ALL_ACCESS, &handle2);
- LookupPrivilegeValue(NULL, SE_DEBUG_NAME, &Luid);
- privilege.PrivilegeCount = 1;
- privilege.Privileges[0].Luid = Luid;
- privilege.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
- AdjustTokenPrivileges(handle2, FALSE, &privilege, sizeof(privilege), NULL, NULL);
- CloseHandle(handle2);
- CloseHandle(handle1);
- }
-
- DWORD GetPIDByProcess(char argv[])
- {
- printf("\n[*] Getting PID...");
- HANDLE hSnapShot;
- PROCESSENTRY32 uProcess;
-
- hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
- uProcess.dwSize = (DWORD) sizeof(PROCESSENTRY32);
-
- int p = 0;
- DWORD PID;
-
- p = Process32First(hSnapShot, &uProcess);
-
- while(p)
- {
- if(strstr(uProcess.szExeFile, argv))
- {
- printf("\n [+]Process found : %s", uProcess.szExeFile);
- PID = uProcess.th32ProcessID;
- printf("\n [+]Process ID : 0x%x", PID);
- return PID;
- }
- p = Process32Next(hSnapShot, &uProcess);
- }
- CloseHandle(hSnapShot);
- return 0;
- }
-
- int main(int args, char *argv[])
- {
- SetDebugPrivilege();
-
- //Recup de la fonction OpenThread dans kernel32.dll
- HMODULE hModDll = NULL;
-
- hModDll = LoadLibrary("kernel32.dll");
- PfOpenT OpenThread = (PfOpenT)GetProcAddress(hModDll, "OpenThread");
-
- ////////////////////////////////////
-
- char Process[100];
- DWORD PID, TID;
- HANDLE hSnapShot, hThread;
- THREADENTRY32 th32;
- CONTEXT Context;
-
- Context.ContextFlags = CONTEXT_FULL;
- printf(" ********* Stack Watcher *********");
-
- cout<<"\n\nProcess you want to analyse : ";
- cin>>Process;
-
- PID = GetPIDByProcess(Process);
-
- //////////////////////////////////////
-
- //On établit la liste de tous les threads
- hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0);
- if(hSnapShot == INVALID_HANDLE_VALUE)
- {
- printf("\n[!]Cannot create process list.\n---- Error with CreateToolhelp32Snapshot() : 0x%x\n\n", GetLastError());
- system("pause");
- return 0;
- }
-
- th32.dwSize = (DWORD) sizeof(THREADENTRY32);
-
- //On se place sur le premier thread
- Thread32First(hSnapShot, &th32);
-
- do
- {
- if(th32.th32OwnerProcessID == PID)
- {
- //On a trouvé un thread qui appartient au processus qu'on veut analyser
-
- TID = th32.th32ThreadID;
-
- printf("\n--------------------\\ Thread ID : 0x%x /--------------------", TID);
-
- /*
- HANDLE WINAPI OpenThread(
- __in DWORD dwDesiredAccess,
- __in BOOL bInheritHandle,
- __in DWORD dwThreadId
- );
- */
-
- //Droits d'accès à un thread : http://msdn2.microsoft.com/en-us/library/ms686769(VS.85).aspx
-
- hThread=OpenThread(THREAD_QUERY_INFORMATION|THREAD_SUSPEND_RESUME|THREAD_GET_CONTEXT, false, TID);
- if(hThread != NULL)
- {
- //On suspend le thread pour récupérer les infos dessus
- SuspendThread(hThread);
-
- //C'est avec cette fonction qu'on va pouvoir récupérer toutes les infos qui nous interressent
- if(!GetThreadContext(hThread, &Context))
- {
- printf("\n[!]Error with GetThreadContext : 0x%x\n\n", GetLastError());
- system("pause");
- return 0;
- }
-
- /*
- typedef struct _CONTEXT {
- DWORD ContextFlags;
- DWORD Dr0;
- DWORD Dr1;
- DWORD Dr2;
- DWORD Dr3;
- DWORD Dr6;
- DWORD Dr7;
- FLOATING_SAVE_AREA FloatSave;
- DWORD SegGs;
- DWORD SegFs;
- DWORD SegEs;
- DWORD SegDs;
- DWORD Edi;
- DWORD Esi;
- DWORD Ebx;
- DWORD Edx;
- DWORD Ecx;
- DWORD Eax;
- DWORD Ebp;
- DWORD Eip;
- DWORD SegCs;
- DWORD EFlags;
- DWORD Esp;
- DWORD SegSs;
- BYTE ExtendedRegisters[MAXIMUM_SUPPORTED_EXTENSION];
- } CONTEXT;
- */
-
- printf("\n\n ***** REGISTERS *****\n");
- printf("\n EAX : 0x%x ---> %d", Context.Eax, Context.Eax);
- printf("\n EBX : 0x%x ---> %d", Context.Ebx, Context.Ebx);
- printf("\n ECX : 0x%x ---> %d", Context.Ecx, Context.Ecx);
- printf("\n EDX : 0x%x ---> %d", Context.Edx, Context.Edx);
- printf("\n ESI : 0x%x ---> %d", Context.Esi, Context.Esi);
- printf("\n EDI : 0x%x ---> %d", Context.Edi, Context.Edi);
- printf("\n EBP : 0x%x ---> %d", Context.Ebp, Context.Ebp);
- printf("\n ESP : 0x%x ---> %d", Context.Esp, Context.Esp);
-
- printf("\n\n ***** DEBUG REGISTERS *****\n");
- printf("\n DR0 : 0x%x ---> %d", Context.Dr0, Context.Dr0);
- printf("\n DR1 : 0x%x ---> %d", Context.Dr1, Context.Dr1);
- printf("\n DR2 : 0x%x ---> %d", Context.Dr2, Context.Dr2);
- printf("\n DR3 : 0x%x ---> %d", Context.Dr3, Context.Dr3);
- /*
- printf("\n DR4 : 0x%x ---> %d", Context.Dr4, Context.Dr4);
- printf("\n DR5 : 0x%x ---> %d", Context.Dr5, Context.Dr5);
- */
- printf("\n DR6 : 0x%x ---> %d", Context.Dr6, Context.Dr6);
- printf("\n DR7 : 0x%x ---> %d", Context.Dr7, Context.Dr7);
-
- printf("\n\n ***** SEGMENTS *****\n");
- printf("\n CS : 0x%x ---> %d", Context.SegCs, Context.SegCs);
- printf("\n DS : 0x%x ---> %d", Context.SegDs, Context.SegDs);
- printf("\n SS : 0x%x ---> %d", Context.SegSs, Context.SegSs);
- printf("\n ES : 0x%x ---> %d", Context.SegEs, Context.SegEs);
- printf("\n FS : 0x%x ---> %d", Context.SegFs, Context.SegFs);
- printf("\n GS : 0x%x ---> %d", Context.SegGs, Context.SegGs);
-
- printf("\n\nEFLAG : 0x%x", Context.EFlags);
-
- //On relance le thread
- ResumeThread(hThread);
-
- CloseHandle(hThread);
- }
- else
- {
- printf("\n[!]Cannot open thread.\n---- Error with OpenThread() : 0x%x\n\n", GetLastError());
- system("pause");
- return 0;
- }
- }
- }while(Thread32Next(hSnapShot, &th32)); // On parcourt tous les threads
-
- cout<<"\n\n";
- CloseHandle(hSnapShot);
- system("pause");
- return 0;
- }
#include <windows.h>
#include <cstdlib>
#include <iostream>
#include <tlhelp32.h>
using namespace std;
typedef HANDLE (__stdcall *PfOpenT)(DWORD, BOOL, DWORD);
DWORD GetPIDByProcess(char argv[]);
void SetDebugPrivilege();
void SetDebugPrivilege(){
TOKEN_PRIVILEGES privilege;
LUID Luid;
HANDLE handle1;
HANDLE handle2;
handle1 = OpenProcess(PROCESS_ALL_ACCESS, FALSE, GetCurrentProcessId());
OpenProcessToken(handle1, TOKEN_ALL_ACCESS, &handle2);
LookupPrivilegeValue(NULL, SE_DEBUG_NAME, &Luid);
privilege.PrivilegeCount = 1;
privilege.Privileges[0].Luid = Luid;
privilege.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
AdjustTokenPrivileges(handle2, FALSE, &privilege, sizeof(privilege), NULL, NULL);
CloseHandle(handle2);
CloseHandle(handle1);
}
DWORD GetPIDByProcess(char argv[])
{
printf("\n[*] Getting PID...");
HANDLE hSnapShot;
PROCESSENTRY32 uProcess;
hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
uProcess.dwSize = (DWORD) sizeof(PROCESSENTRY32);
int p = 0;
DWORD PID;
p = Process32First(hSnapShot, &uProcess);
while(p)
{
if(strstr(uProcess.szExeFile, argv))
{
printf("\n [+]Process found : %s", uProcess.szExeFile);
PID = uProcess.th32ProcessID;
printf("\n [+]Process ID : 0x%x", PID);
return PID;
}
p = Process32Next(hSnapShot, &uProcess);
}
CloseHandle(hSnapShot);
return 0;
}
int main(int args, char *argv[])
{
SetDebugPrivilege();
//Recup de la fonction OpenThread dans kernel32.dll
HMODULE hModDll = NULL;
hModDll = LoadLibrary("kernel32.dll");
PfOpenT OpenThread = (PfOpenT)GetProcAddress(hModDll, "OpenThread");
////////////////////////////////////
char Process[100];
DWORD PID, TID;
HANDLE hSnapShot, hThread;
THREADENTRY32 th32;
CONTEXT Context;
Context.ContextFlags = CONTEXT_FULL;
printf(" ********* Stack Watcher *********");
cout<<"\n\nProcess you want to analyse : ";
cin>>Process;
PID = GetPIDByProcess(Process);
//////////////////////////////////////
//On établit la liste de tous les threads
hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0);
if(hSnapShot == INVALID_HANDLE_VALUE)
{
printf("\n[!]Cannot create process list.\n---- Error with CreateToolhelp32Snapshot() : 0x%x\n\n", GetLastError());
system("pause");
return 0;
}
th32.dwSize = (DWORD) sizeof(THREADENTRY32);
//On se place sur le premier thread
Thread32First(hSnapShot, &th32);
do
{
if(th32.th32OwnerProcessID == PID)
{
//On a trouvé un thread qui appartient au processus qu'on veut analyser
TID = th32.th32ThreadID;
printf("\n--------------------\\ Thread ID : 0x%x /--------------------", TID);
/*
HANDLE WINAPI OpenThread(
__in DWORD dwDesiredAccess,
__in BOOL bInheritHandle,
__in DWORD dwThreadId
);
*/
//Droits d'accès à un thread : http://msdn2.microsoft.com/en-us/library/ms686769(VS.85).aspx
hThread=OpenThread(THREAD_QUERY_INFORMATION|THREAD_SUSPEND_RESUME|THREAD_GET_CONTEXT, false, TID);
if(hThread != NULL)
{
//On suspend le thread pour récupérer les infos dessus
SuspendThread(hThread);
//C'est avec cette fonction qu'on va pouvoir récupérer toutes les infos qui nous interressent
if(!GetThreadContext(hThread, &Context))
{
printf("\n[!]Error with GetThreadContext : 0x%x\n\n", GetLastError());
system("pause");
return 0;
}
/*
typedef struct _CONTEXT {
DWORD ContextFlags;
DWORD Dr0;
DWORD Dr1;
DWORD Dr2;
DWORD Dr3;
DWORD Dr6;
DWORD Dr7;
FLOATING_SAVE_AREA FloatSave;
DWORD SegGs;
DWORD SegFs;
DWORD SegEs;
DWORD SegDs;
DWORD Edi;
DWORD Esi;
DWORD Ebx;
DWORD Edx;
DWORD Ecx;
DWORD Eax;
DWORD Ebp;
DWORD Eip;
DWORD SegCs;
DWORD EFlags;
DWORD Esp;
DWORD SegSs;
BYTE ExtendedRegisters[MAXIMUM_SUPPORTED_EXTENSION];
} CONTEXT;
*/
printf("\n\n ***** REGISTERS *****\n");
printf("\n EAX : 0x%x ---> %d", Context.Eax, Context.Eax);
printf("\n EBX : 0x%x ---> %d", Context.Ebx, Context.Ebx);
printf("\n ECX : 0x%x ---> %d", Context.Ecx, Context.Ecx);
printf("\n EDX : 0x%x ---> %d", Context.Edx, Context.Edx);
printf("\n ESI : 0x%x ---> %d", Context.Esi, Context.Esi);
printf("\n EDI : 0x%x ---> %d", Context.Edi, Context.Edi);
printf("\n EBP : 0x%x ---> %d", Context.Ebp, Context.Ebp);
printf("\n ESP : 0x%x ---> %d", Context.Esp, Context.Esp);
printf("\n\n ***** DEBUG REGISTERS *****\n");
printf("\n DR0 : 0x%x ---> %d", Context.Dr0, Context.Dr0);
printf("\n DR1 : 0x%x ---> %d", Context.Dr1, Context.Dr1);
printf("\n DR2 : 0x%x ---> %d", Context.Dr2, Context.Dr2);
printf("\n DR3 : 0x%x ---> %d", Context.Dr3, Context.Dr3);
/*
printf("\n DR4 : 0x%x ---> %d", Context.Dr4, Context.Dr4);
printf("\n DR5 : 0x%x ---> %d", Context.Dr5, Context.Dr5);
*/
printf("\n DR6 : 0x%x ---> %d", Context.Dr6, Context.Dr6);
printf("\n DR7 : 0x%x ---> %d", Context.Dr7, Context.Dr7);
printf("\n\n ***** SEGMENTS *****\n");
printf("\n CS : 0x%x ---> %d", Context.SegCs, Context.SegCs);
printf("\n DS : 0x%x ---> %d", Context.SegDs, Context.SegDs);
printf("\n SS : 0x%x ---> %d", Context.SegSs, Context.SegSs);
printf("\n ES : 0x%x ---> %d", Context.SegEs, Context.SegEs);
printf("\n FS : 0x%x ---> %d", Context.SegFs, Context.SegFs);
printf("\n GS : 0x%x ---> %d", Context.SegGs, Context.SegGs);
printf("\n\nEFLAG : 0x%x", Context.EFlags);
//On relance le thread
ResumeThread(hThread);
CloseHandle(hThread);
}
else
{
printf("\n[!]Cannot open thread.\n---- Error with OpenThread() : 0x%x\n\n", GetLastError());
system("pause");
return 0;
}
}
}while(Thread32Next(hSnapShot, &th32)); // On parcourt tous les threads
cout<<"\n\n";
CloseHandle(hSnapShot);
system("pause");
return 0;
}
Sources du même auteur
Sources de la même categorie
Commentaires et avis
Discussions en rapport avec ce code source dans le forum
Utilisation de stack en C++ [ par jagdjg ]
J essaie de faire un stack mais ca ne marche pas La declaration est : Stack* pile = new Stack();le push : pile->Push(strPile);le pop : strPile = pi
[C] Généricité et cast automatique. [ par LocalStone ]
Salut, Alors voilà ... Je me posais la question suivante : existe-t-il un moyen en C de gérer la généricité de manière transparente ? Je m'explique ..
Pile de double [ par Pof ]
Bonjour ! voilà j'ai un petit problème avec les std::stack :std::stack<double> stack;stack.push(20);stack.push(10);[...]double a = sta
Win32 - parcourir la pile utilisateur d'un thread [ par BlackGoddess ]
Bonjour, je voudrais parcourir la pile utilisateur d'un thread. J'ai essayé en utilisant GetThreadContext, en sauvegardant Esp a la cré
stack et char * [ par yuriashford ]
Salut à tous je developpe actuellement une application qui utilise une stack de STL la stack est une declaré : stack<char *> pil
Perte de messages [ par mohdaef ]
Bonjour à tous Je suis entrain de programmer un petit multijoueur, et pour cela je doit échanger des messages entre les différents programmes. Pour
Envoi de message à windowProcedure [ par mohdaef ]
Bonsoir Je souhaite envoyer un message personalisé depuis un thread à windowProcedure(...), pour qu'il soit traité comme n'importe quel autre message
programme qui rassemble plusieurs petits programmes [ par imanova002 ]
bonjour, j suis une débutante en programmation C, a peine j'essaie de faire des programmes de comparaison d'addition d nombres ... Mon problème c'est
Problemes avec l'importation du "msado15.idl" [ par khaliloenit ]
Après avoir importé le fichier IDL "msado15.idl" dans le fichier IDL de ma DLL et la compilation, j'ai beaucoup d'erreurs comme ceci: 1>c:\sac\see_ac
Thread [ par malkommalkom ]
Bonjour a tous, Ma question est simple mais dificile a posé J'ai consu un server multy-client, donc avec des thread. Ces threads accedent, lors de c
|
Derniers Blogs
FAIRE APPARAITRE L'ONGLET 'DéVELOPPEUR' DANS OFFICE 2010FAIRE APPARAITRE L'ONGLET 'DéVELOPPEUR' DANS OFFICE 2010 par neodante
La nouvelle interface d'Office 2010 à amener quelques modifications par rapport à celle de 2007. Certes mineures, ces modifications ont fait disparaître la case à cocher de l'onglet 'Développeur' en première page du panneau du 'bouton Office' (dans Office...
Cliquez pour lire la suite de l'article par neodante [ASTUCE] PATCH POUR MICROSOFT FORUMS NNTP BRIDGE V1[ASTUCE] PATCH POUR MICROSOFT FORUMS NNTP BRIDGE V1 par pierre
Si vous avez téléchargé comme moi Microsoft Forums NNTP Bridge V1 avant le 11 mars 2010 (voir [Astuce] Disponibilité de Microsoft Forum NNTP Bridge Version 1.0), un problème de date localisée pour les non anglais était présent. Un patch est disponibl...
Cliquez pour lire la suite de l'article par pierre PB LORS DE L'INSTALLATION SHAREPOINT 2010.PB LORS DE L'INSTALLATION SHAREPOINT 2010. par Patrick Guimonet
Lors de l'installation de SharePoint 2010, j'ai rencontré un problème de plantage à l'étape 5 du configuration Wizard. Ca se termine sur cet écran : Et en analysant le fichier de journalisation, on remarque vers la fin des 15000 et quelques lign...
Cliquez pour lire la suite de l'article par Patrick Guimonet [WF4] AJOUTER DES CONTRAINTES à UNE ACTIVITé (2/2)[WF4] AJOUTER DES CONTRAINTES à UNE ACTIVITé (2/2) par JeremyJeanson
Après mon précédent article qui attaque les contraintes par la fasse Nord de l'Everest. passons à la seconde possibilité offerte par WF4 pour valider une activité : la metadata . Je vous en ai déjà toucher un ou deux mots. La metadata dans WF4 est un élém...
Cliquez pour lire la suite de l'article par JeremyJeanson [WF4] AJOUTER DES CONTRAINTES à UNE ACTIVITé (1/2)[WF4] AJOUTER DES CONTRAINTES à UNE ACTIVITé (1/2) par JeremyJeanson
De WF3 à WF4 pas mal de choses on été changées pour faciliter la vie des développeurs, mais certain points peuvent sembler obscures. comme les contraintes. Pour vous guider, je me lance dans une série de deux articles. Ils présenterons deux approches poss...
Cliquez pour lire la suite de l'article par JeremyJeanson
Logiciels
Xilisoft Convertisseur Vidéo Ultimate (5.1.39.0305)XILISOFT CONVERTISSEUR VIDéO ULTIMATE (5.1.39.0305)Xilisoft Convertisseur Vidéo Ultimate est un outil puissant de conversion vidéo, facile à utilise... Cliquez pour télécharger Xilisoft Convertisseur Vidéo Ultimate Xilisoft DVD Ripper Ultimate (5.0.64.0304)XILISOFT DVD RIPPER ULTIMATE (5.0.64.0304)Xilisoft DVD Ripper Ultimate est un logiciel excellent pour copier et convertir DVD vers presque ... Cliquez pour télécharger Xilisoft DVD Ripper Ultimate Rigs of Rods (63.3)RIGS OF RODS (63.3)c'est un jeu de multi-simulation camions,autobus voitures, avions, bateaux, hélicoptère avec défo... Cliquez pour télécharger Rigs of Rods Konvertor (4.00)KONVERTOR (4.00)Le logiciel est un gestionnaire multimedia affichant, jouant et convertissant plus de 2000 format... Cliquez pour télécharger Konvertor
Comparez les prix

HTC Magic
Entre 429€ et 429€
|