1 // copyright (c) 2021 hors<horsicq@gmail.com>
2 //
3 // Permission is hereby granted, free of charge, to any person obtaining a copy
4 // of this software and associated documentation files (the "Software"), to deal
5 // in the Software without restriction, including without limitation the rights
6 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 // copies of the Software, and to permit persons to whom the Software is
8 // furnished to do so, subject to the following conditions:
9 
10 // The above copyright notice and this permission notice shall be included in all
11 // copies or substantial portions of the Software.
12 
13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19 // SOFTWARE.
20 //
21 #include "xshortcuts.h"
22 
XShortcuts(QObject * pParent)23 XShortcuts::XShortcuts(QObject *pParent) : QObject(pParent)
24 {
25     g_bIsNative=false;
26 }
27 
setName(QString sValue)28 void XShortcuts::setName(QString sValue)
29 {
30     this->g_sName=sValue;
31 }
32 
setNative(bool bValue)33 void XShortcuts::setNative(bool bValue)
34 {
35     g_bIsNative=bValue;
36 }
37 
addGroup(GROUPID groupId)38 void XShortcuts::addGroup(GROUPID groupId)
39 {
40     qint32 nEnd=getGroupEnd(groupId);
41 
42     for(qint32 nId=(groupId<<GROUP_SH)+1;nId<nEnd;nId++)
43     {
44         g_listValueIDs.append((XShortcuts::ID)nId);
45     }
46 }
47 
addGroup(ID id)48 void XShortcuts::addGroup(ID id)
49 {
50     qint32 nEnd=getGroupEnd((GROUPID)(id>>GROUP_SH));
51 
52     for(qint32 nId=id+1;nId<nEnd;nId++)
53     {
54         g_listValueIDs.append((XShortcuts::ID)nId);
55     }
56 }
57 
setShortcutsIDs(QList<XShortcuts::ID> listValueIDs)58 void XShortcuts::setShortcutsIDs(QList<XShortcuts::ID> listValueIDs)
59 {
60     this->g_listValueIDs=listValueIDs;
61 }
62 
getShortcutsIDs()63 QList<XShortcuts::ID> XShortcuts::getShortcutsIDs()
64 {
65     return g_listValueIDs;
66 }
67 
load()68 void XShortcuts::load()
69 {
70     QSettings *pSettings=nullptr;
71 
72     if(g_bIsNative)
73     {
74         pSettings=new QSettings;
75     }
76     else if(g_sName!="")
77     {
78         pSettings=new QSettings(qApp->applicationDirPath()+QDir::separator()+QString("%1").arg(g_sName),QSettings::IniFormat); // TODO more options
79     }
80 
81 #ifdef QT_DEBUG
82     if(pSettings)
83     {
84         qDebug("XShortcuts load %s",pSettings->fileName().toLatin1().data());
85     }
86 #endif
87 
88     int nNumberOfIDs=g_listValueIDs.count();
89 
90     for(int i=0;i<nNumberOfIDs;i++)
91     {
92         ID id=g_listValueIDs.at(i);
93         QString sName=idToSettingsString(id);
94         QKeySequence ksDefault=getDefault(id);
95 
96         if(pSettings)
97         {
98             g_mapValues.insert(id,QKeySequence::fromString(pSettings->value(sName,ksDefault.toString()).toString()));
99         }
100         else
101         {
102             g_mapValues.insert(id,ksDefault);
103         }
104     }
105 
106     if(pSettings)
107     {
108         delete pSettings;
109     }
110 }
111 
save()112 void XShortcuts::save()
113 {
114     QSettings *pSettings=nullptr;
115 
116     if(g_bIsNative)
117     {
118         pSettings=new QSettings;
119     }
120     else if(g_sName!="")
121     {
122         pSettings=new QSettings(qApp->applicationDirPath()+QDir::separator()+QString("%1").arg(g_sName),QSettings::IniFormat); // TODO more options
123     }
124 
125 #ifdef QT_DEBUG
126     if(pSettings)
127     {
128         qDebug("XShortcuts save %s",pSettings->fileName().toLatin1().data());
129     }
130 #endif
131 
132     if(pSettings)
133     {
134         int nNumberOfIDs=g_listValueIDs.count();
135 
136         for(int i=0;i<nNumberOfIDs;i++)
137         {
138             ID id=g_listValueIDs.at(i);
139             QString sName=idToSettingsString(id);
140             pSettings->setValue(sName,g_mapValues.value(id).toString());
141         }
142     }
143 
144     if(pSettings)
145     {
146         delete pSettings;
147     }
148 }
149 
getShortcut(XShortcuts::ID id)150 QKeySequence XShortcuts::getShortcut(XShortcuts::ID id)
151 {
152 #ifdef QT_DEBUG
153     if(!g_mapValues.contains(id))
154     {
155         QString sErrorString=idToSettingsString(id);
156         qDebug(sErrorString.toLatin1().data());
157     }
158 #endif
159     return g_mapValues.value(id);
160 }
161 
setShortcut(XShortcuts::ID id,QKeySequence keyValue)162 void XShortcuts::setShortcut(XShortcuts::ID id, QKeySequence keyValue)
163 {
164     g_mapValues.insert(id,keyValue);
165 }
166 
checkShortcut(XShortcuts::ID id,QKeySequence keyValue)167 bool XShortcuts::checkShortcut(XShortcuts::ID id, QKeySequence keyValue)
168 {
169     bool bResult=true;
170 
171     if(keyValue!=QKeySequence())
172     {
173         GROUPID idGroup=getGroupId(id);
174 
175         for(qint32 nId=(idGroup<<GROUP_SH)+1;nId<getGroupEnd(idGroup);nId++)
176         {
177             if(id!=nId)
178             {
179                 if(getShortcut((ID)nId)==keyValue)
180                 {
181                     bResult=false;
182                     break;
183                 }
184             }
185         }
186     }
187 
188     return bResult;
189 }
190 
idToSettingsString(XShortcuts::ID id)191 QString XShortcuts::idToSettingsString(XShortcuts::ID id)
192 {
193     QString sResult="Unknown";
194 
195     switch(id)
196     {
197         case ID_ACTION_COPY:                        sResult=QString("Shortcuts/Action/Copy");                       break;
198         case ID_STRINGS_COPYSTRING:                 sResult=QString("Shortcuts/Strings/CopyString");                break;
199         case ID_STRINGS_COPYOFFSET:                 sResult=QString("Shortcuts/Strings/CopyOffset");                break;
200         case ID_STRINGS_COPYSIZE:                   sResult=QString("Shortcuts/Strings/CopySize");                  break;
201         case ID_STRINGS_HEX:                        sResult=QString("Shortcuts/Strings/Hex");                       break;
202         case ID_STRINGS_DEMANGLE:                   sResult=QString("Shortcuts/Strings/Demangle");                  break;
203         case ID_SIGNATURES_COPYNAME:                sResult=QString("Shortcuts/Signatures/CopyName");               break;
204         case ID_SIGNATURES_COPYSIGNATURE:           sResult=QString("Shortcuts/Signatures/CopySignature");          break;
205         case ID_SIGNATURES_COPYADDRESS:             sResult=QString("Shortcuts/Signatures/CopyAddress");            break;
206         case ID_SIGNATURES_COPYOFFSET:              sResult=QString("Shortcuts/Signatures/CopyOffset");             break;
207         case ID_SIGNATURES_COPYSIZE:                sResult=QString("Shortcuts/Signatures/CopySize");               break;
208         case ID_SIGNATURES_HEX:                     sResult=QString("Shortcuts/Signatures/Hex");                    break;
209         case ID_HEX_DUMPTOFILE:                     sResult=QString("Shortcuts/Hex/DumpToFile");                    break;
210         case ID_HEX_GOTOADDRESS:                    sResult=QString("Shortcuts/Hex/GoToAddress");                   break;
211         case ID_HEX_GOTOOFFSET:                     sResult=QString("Shortcuts/Hex/GoToOffset");                    break;
212         case ID_HEX_SIGNATURE:                      sResult=QString("Shortcuts/Hex/Signature");                     break;
213         case ID_HEX_FIND:                           sResult=QString("Shortcuts/Hex/Find");                          break;
214         case ID_HEX_FINDNEXT:                       sResult=QString("Shortcuts/Hex/FindNext");                      break;
215         case ID_HEX_SELECTALL:                      sResult=QString("Shortcuts/Hex/SelectAll");                     break;
216         case ID_HEX_COPYASHEX:                      sResult=QString("Shortcuts/Hex/CopyAsHex");                     break;
217         case ID_HEX_COPYCURSOROFFSET:               sResult=QString("Shortcuts/Hex/CopyCursorOffset");              break;
218         case ID_HEX_COPYCURSORADDRESS:              sResult=QString("Shortcuts/Hex/CopyCursorAddress");             break;
219         case ID_HEX_DISASM:                         sResult=QString("Shortcuts/Hex/Disasm");                        break;
220         case ID_HEX_MEMORYMAP:                      sResult=QString("Shortcuts/Hex/MemoryMap");                     break;
221         case ID_DISASM_DUMPTOFILE:                  sResult=QString("Shortcuts/Disasm/DumpToFile");                 break;
222         case ID_DISASM_GOTOADDRESS:                 sResult=QString("Shortcuts/Disasm/GoToAddress");                break;
223         case ID_DISASM_GOTOOFFSET:                  sResult=QString("Shortcuts/Disasm/GoToOffset");                 break;
224         case ID_DISASM_GOTOENTRYPOINT:              sResult=QString("Shortcuts/Disasm/GoToEntryPoint");             break;
225         case ID_DISASM_HEXSIGNATURE:                sResult=QString("Shortcuts/Disasm/HexSignature");               break;
226         case ID_DISASM_SIGNATURE:                   sResult=QString("Shortcuts/Disasm/Signature");                  break;
227         case ID_DISASM_FIND:                        sResult=QString("Shortcuts/Disasm/Find");                       break;
228         case ID_DISASM_FINDNEXT:                    sResult=QString("Shortcuts/Disasm/FindNext");                   break;
229         case ID_DISASM_SELECTALL:                   sResult=QString("Shortcuts/Disasm/SelectAll");                  break;
230         case ID_DISASM_COPYASHEX:                   sResult=QString("Shortcuts/Disasm/CopyAsHex");                  break;
231         case ID_DISASM_COPYCURSOROFFSET:            sResult=QString("Shortcuts/Disasm/CopyCursorOffset");           break;
232         case ID_DISASM_COPYCURSORADDRESS:           sResult=QString("Shortcuts/Disasm/CopyCursorAddress");          break;
233         case ID_DISASM_HEX:                         sResult=QString("Shortcuts/Disasm/Hex");                        break;
234         case ID_DEBUGGER_FILE_OPEN:                 sResult=QString("Shortcuts/Debugger/File/Open");                break;
235         case ID_DEBUGGER_FILE_CLOSE:                sResult=QString("Shortcuts/Debugger/File/Close");               break;
236         case ID_DEBUGGER_FILE_EXIT:                 sResult=QString("Shortcuts/Debugger/File/Exit");                break;
237         case ID_DEBUGGER_VIEW_CPU:                  sResult=QString("Shortcuts/Debugger/View/CPU");                 break;
238         case ID_DEBUGGER_VIEW_ACTIONS:              sResult=QString("Shortcuts/Debugger/View/Actions");             break;
239         case ID_DEBUGGER_VIEW_LOG:                  sResult=QString("Shortcuts/Debugger/View/Log");                 break;
240         case ID_DEBUGGER_VIEW_BREAKPOINTS:          sResult=QString("Shortcuts/Debugger/View/Breakpoints");         break;
241         case ID_DEBUGGER_VIEW_MEMORYMAP:            sResult=QString("Shortcuts/Debugger/View/MemoryMap");           break;
242         case ID_DEBUGGER_VIEW_CALLSTACK:            sResult=QString("Shortcuts/Debugger/View/CallStack");           break;
243         case ID_DEBUGGER_VIEW_THREADS:              sResult=QString("Shortcuts/Debugger/View/Threads");             break;
244         case ID_DEBUGGER_VIEW_HANDLES:              sResult=QString("Shortcuts/Debugger/View/Handles");             break;
245         case ID_DEBUGGER_DEBUG_RUN:                 sResult=QString("Shortcuts/Debugger/Debug/Run");                break;
246         case ID_DEBUGGER_DEBUG_PAUSE:               sResult=QString("Shortcuts/Debugger/Debug/Pause");              break;
247         case ID_DEBUGGER_DEBUG_SETREMOVEBREAKPOINT: sResult=QString("Shortcuts/Debugger/Debug/SetBreakpoint");      break;
248         case ID_DEBUGGER_DEBUG_STEPINTO:            sResult=QString("Shortcuts/Debugger/Debug/StepInto");           break;
249         case ID_DEBUGGER_DEBUG_STEPOVER:            sResult=QString("Shortcuts/Debugger/Debug/StepOver");           break;
250         case ID_DEBUGGER_DEBUG_STOP:                sResult=QString("Shortcuts/Debugger/Debug/Stop");               break;
251         case ID_DEBUGGER_DEBUG_RESTART:             sResult=QString("Shortcuts/Debugger/Debug/Restart");            break;
252         case ID_DEBUGGER_FILE_ATTACH:               sResult=QString("Shortcuts/Debugger/File/Attach");              break;
253         case ID_DEBUGGER_FILE_DETACH:               sResult=QString("Shortcuts/Debugger/File/Detach");              break;
254         case ID_DEBUGGER_DISASM_DUMPTOFILE:         sResult=QString("Shortcuts/Debugger/Disasm/DumpToFile");        break;
255         case ID_DEBUGGER_DISASM_GOTOADDRESS:        sResult=QString("Shortcuts/Debugger/Disasm/GoToAddress");       break;
256         case ID_DEBUGGER_DISASM_HEXSIGNATURE:       sResult=QString("Shortcuts/Debugger/Disasm/HexSignature");      break;
257         case ID_DEBUGGER_DISASM_SIGNATURE:          sResult=QString("Shortcuts/Debugger/Disasm/Signature");         break;
258         case ID_DEBUGGER_DISASM_FIND:               sResult=QString("Shortcuts/Debugger/Disasm/Find");              break;
259         case ID_DEBUGGER_DISASM_FINDNEXT:           sResult=QString("Shortcuts/Debugger/Disasm/FindNext");          break;
260         case ID_DEBUGGER_DISASM_COPYASHEX:          sResult=QString("Shortcuts/Debugger/Disasm/CopyAsHex");         break;
261         case ID_DEBUGGER_DISASM_COPYCURSORADDRESS:  sResult=QString("Shortcuts/Debugger/Disasm/CopyCursorAddress"); break;
262         case ID_DEBUGGER_HEX_DUMPTOFILE:            sResult=QString("Shortcuts/Debugger/Hex/DumpToFile");           break;
263         case ID_DEBUGGER_HEX_GOTOADDRESS:           sResult=QString("Shortcuts/Debugger/Hex/GoToAddress");          break;
264         case ID_ARCHIVE_COPYFILENAME:               sResult=QString("Shortcuts/Archive/CopyFilename");              break;
265         case ID_ARCHIVE_DUMPTOFILE:                 sResult=QString("Shortcuts/Archive/DumpToFile");                break;
266         case ID_ARCHIVE_ENTROPY:                    sResult=QString("Shortcuts/Archive/Entropy");                   break;
267         case ID_ARCHIVE_HASH:                       sResult=QString("Shortcuts/Archive/Hash");                      break;
268         case ID_ARCHIVE_HEX:                        sResult=QString("Shortcuts/Archive/Hex");                       break;
269         case ID_ARCHIVE_OPEN:                       sResult=QString("Shortcuts/Archive/Open");                      break;
270         case ID_ARCHIVE_SCAN:                       sResult=QString("Shortcuts/Archive/Scan");                      break;
271         case ID_ARCHIVE_STRINGS:                    sResult=QString("Shortcuts/Archive/Strings");                   break;
272         case ID_TABLE_HEX:                          sResult=QString("Shortcuts/Table/Hex");                         break;
273         case ID_TABLE_DISASM:                       sResult=QString("Shortcuts/Table/Disasm");                      break;
274         default:
275         {
276         #ifdef QT_DEBUG
277             qDebug("UNKNOWN!!!");
278         #endif
279         }
280     }
281 
282     return sResult;
283 }
284 
idToString(XShortcuts::ID id)285 QString XShortcuts::idToString(XShortcuts::ID id)
286 {
287     QString sResult=tr("Unknown");
288 
289     switch(id)
290     {
291         case ID_ACTION_COPY:
292             sResult=tr("Copy");
293             break;
294         case ID_STRINGS_COPYSTRING:
295             sResult=tr("Copy string");
296             break;
297         case ID_STRINGS_COPYOFFSET:
298             sResult=tr("Copy offset");
299             break;
300         case ID_STRINGS_COPYSIZE:
301             sResult=tr("Copy size");
302             break;
303         case ID_STRINGS_HEX:
304             sResult=tr("Hex");
305             break;
306         case ID_STRINGS_DEMANGLE:
307             sResult=tr("Demangle");
308             break;
309         case ID_SIGNATURES_COPYNAME:
310             sResult=tr("Copy name");
311             break;
312         case ID_SIGNATURES_COPYSIGNATURE:
313             sResult=tr("Copy signature");
314             break;
315         case ID_SIGNATURES_COPYADDRESS:
316             sResult=tr("Copy address");
317             break;
318         case ID_SIGNATURES_COPYOFFSET:
319             sResult=tr("Copy offset");
320             break;
321         case ID_SIGNATURES_COPYSIZE:
322             sResult=tr("Copy size");
323             break;
324         case ID_TABLE_HEX:
325         case ID_DISASM_HEX:
326         case ID_SIGNATURES_HEX:
327             sResult=tr("Hex");
328             break;
329         case ID_HEX_DUMPTOFILE:
330         case ID_DEBUGGER_HEX_DUMPTOFILE:
331         case ID_DEBUGGER_DISASM_DUMPTOFILE:
332         case ID_ARCHIVE_DUMPTOFILE:
333             sResult=tr("Dump to file");
334             break;
335         case ID_DISASM_GOTOADDRESS:
336         case ID_DEBUGGER_HEX_GOTOADDRESS:
337         case ID_DEBUGGER_DISASM_GOTOADDRESS:
338         case ID_HEX_GOTOADDRESS:
339             sResult=tr("Go to address");
340             break;
341         case ID_DISASM_GOTOOFFSET:
342         case ID_HEX_GOTOOFFSET:
343             sResult=tr("Go to offset");
344             break;
345         case ID_DEBUGGER_DISASM_SIGNATURE:
346         case ID_DISASM_SIGNATURE:
347         case ID_HEX_SIGNATURE:
348             sResult=tr("Signature");
349             break;
350         case ID_DISASM_FIND:
351         case ID_DEBUGGER_DISASM_FIND:
352         case ID_HEX_FIND:
353             sResult=tr("Find");
354             break;
355         case ID_DEBUGGER_DISASM_FINDNEXT:
356         case ID_HEX_FINDNEXT:
357         case ID_DISASM_FINDNEXT:
358             sResult=tr("Find next");
359             break;
360         case ID_HEX_SELECTALL:                      sResult=tr("Select all");                   break;
361         case ID_HEX_COPYASHEX:                      sResult=tr("Copy as hex");                  break;
362         case ID_HEX_COPYCURSOROFFSET:               sResult=tr("Copy cursor offset");           break;
363         case ID_HEX_COPYCURSORADDRESS:              sResult=tr("Copy cursor address");          break;
364         case ID_TABLE_DISASM:
365         case ID_HEX_DISASM:
366             sResult=tr("Disasm");
367             break;
368         case ID_HEX_MEMORYMAP:                      sResult=tr("Memory map");                   break;
369         case ID_DISASM_DUMPTOFILE:                  sResult=tr("Dump to file");                 break;
370         case ID_DISASM_GOTOENTRYPOINT:              sResult=tr("Go to entry point");            break;
371         case ID_DISASM_HEXSIGNATURE:                sResult=tr("Hex signature");                break;
372         case ID_DISASM_SELECTALL:                   sResult=tr("Select all");                   break;
373         case ID_DISASM_COPYASHEX:                   sResult=tr("Copy as hex");                  break;
374         case ID_DISASM_COPYCURSORADDRESS:           sResult=tr("Copy cursor address");          break;
375         case ID_DISASM_COPYCURSOROFFSET:            sResult=tr("Copy cursor offset");           break;
376         case ID_DEBUGGER_FILE_OPEN:                 sResult=tr("Open");                         break;
377         case ID_DEBUGGER_FILE_ATTACH:               sResult=tr("Attach");                       break;
378         case ID_DEBUGGER_FILE_DETACH:               sResult=tr("Detach");                       break;
379         case ID_DEBUGGER_FILE_CLOSE:                sResult=tr("Close");                        break;
380         case ID_DEBUGGER_FILE_EXIT:                 sResult=tr("Exit");                         break;
381         case ID_DEBUGGER_VIEW_CPU:                  sResult=tr("CPU");                          break;
382         case ID_DEBUGGER_VIEW_ACTIONS:              sResult=tr("Actions");                      break;
383         case ID_DEBUGGER_VIEW_LOG:                  sResult=tr("Log");                          break;
384         case ID_DEBUGGER_VIEW_BREAKPOINTS:          sResult=tr("Breakpoints");                  break;
385         case ID_DEBUGGER_VIEW_MEMORYMAP:            sResult=tr("Memory map");                   break;
386         case ID_DEBUGGER_VIEW_CALLSTACK:            sResult=tr("Call stack");                   break;
387         case ID_DEBUGGER_VIEW_THREADS:              sResult=tr("Threads");                      break;
388         case ID_DEBUGGER_VIEW_HANDLES:              sResult=tr("Handles");                      break;
389         case ID_DEBUGGER_DEBUG_RUN:                 sResult=tr("Run");                          break;
390         case ID_DEBUGGER_DEBUG_PAUSE:               sResult=tr("Pause");                        break;
391         case ID_DEBUGGER_DEBUG_SETREMOVEBREAKPOINT: sResult=tr("Set breakpoint");               break;
392         case ID_DEBUGGER_DEBUG_STEPINTO:            sResult=tr("Step into");                    break;
393         case ID_DEBUGGER_DEBUG_STEPOVER:            sResult=tr("Step over");                    break;
394         case ID_DEBUGGER_DEBUG_STOP:                sResult=tr("Stop");                         break;
395         case ID_DEBUGGER_DEBUG_RESTART:             sResult=tr("Restart");                      break;
396         case ID_DEBUGGER_DISASM_HEXSIGNATURE:       sResult=tr("Hex signature");                break;
397         case ID_DEBUGGER_DISASM_COPYASHEX:          sResult=tr("Copy as hex");                  break;
398         case ID_DEBUGGER_DISASM_COPYCURSORADDRESS:  sResult=tr("Copy cursor address");          break;
399         case ID_ARCHIVE_COPYFILENAME:               sResult=tr("Copy filename");                break;
400         case ID_ARCHIVE_ENTROPY:                    sResult=tr("Entropy");                      break;
401         case ID_ARCHIVE_HASH:                       sResult=tr("Hash");                         break;
402         case ID_ARCHIVE_HEX:                        sResult=tr("Hex");                          break;
403         case ID_ARCHIVE_OPEN:                       sResult=tr("Open");                         break;
404         case ID_ARCHIVE_SCAN:                       sResult=tr("Scan");                         break;
405         case ID_ARCHIVE_STRINGS:                    sResult=tr("Strings");                      break;
406         default:                                    sResult=tr("Unknown");
407     }
408 
409     return sResult;
410 }
411 
getDefault(XShortcuts::ID id)412 QKeySequence XShortcuts::getDefault(XShortcuts::ID id)
413 {
414     QKeySequence ksResult=QKeySequence();
415 
416     switch(id)
417     {
418         case ID_ACTION_COPY:
419             ksResult=QKeySequence::Copy;
420             break;
421         case ID_STRINGS_COPYSTRING:
422             ksResult=QKeySequence::Copy;
423             break;
424         case ID_STRINGS_COPYOFFSET:
425             ksResult=QKeySequence();
426             break;
427         case ID_STRINGS_COPYSIZE:
428             ksResult=QKeySequence();
429             break;
430         case ID_STRINGS_HEX:
431             ksResult=QKeySequence();
432             break;
433         case ID_STRINGS_DEMANGLE:
434             ksResult=QKeySequence();
435             break;
436         case ID_SIGNATURES_COPYNAME:
437             ksResult=QKeySequence::Copy;
438             break;
439         case ID_SIGNATURES_COPYSIGNATURE:
440             ksResult=QKeySequence();
441             break;
442         case ID_SIGNATURES_COPYADDRESS:
443             ksResult=QKeySequence();
444             break;
445         case ID_SIGNATURES_COPYOFFSET:
446             ksResult=QKeySequence();
447             break;
448         case ID_SIGNATURES_COPYSIZE:
449             ksResult=QKeySequence();
450             break;
451         case ID_SIGNATURES_HEX:
452             ksResult=QKeySequence();
453             break;
454         case ID_HEX_DUMPTOFILE:
455             ksResult=Qt::CTRL+Qt::Key_D;
456             break;
457         case ID_HEX_GOTOADDRESS:
458             ksResult=Qt::CTRL+Qt::Key_G;
459             break;
460         case ID_HEX_GOTOOFFSET:
461             ksResult=QKeySequence();
462             break;
463         case ID_HEX_SIGNATURE:
464             ksResult=Qt::Key_S;
465             break;
466         case ID_HEX_FIND:
467             ksResult=QKeySequence::Find;
468             break;
469         case ID_HEX_FINDNEXT:
470             ksResult=QKeySequence::FindNext;
471             break;
472         case ID_HEX_SELECTALL:
473             ksResult=QKeySequence::SelectAll;
474             break;
475         case ID_HEX_COPYASHEX:
476             ksResult=QKeySequence::Copy;
477             break;
478         case ID_HEX_COPYCURSOROFFSET:
479             ksResult=QKeySequence();
480             break;
481         case ID_HEX_COPYCURSORADDRESS:
482             ksResult=QKeySequence();
483             break;
484         case ID_HEX_DISASM:
485             ksResult=QKeySequence();
486             break;
487         case ID_HEX_MEMORYMAP:
488             ksResult=QKeySequence();
489             break;
490         case ID_DISASM_DUMPTOFILE:
491             ksResult=Qt::CTRL+Qt::Key_D;
492             break;
493         case ID_DISASM_GOTOADDRESS:
494             ksResult=Qt::CTRL+Qt::Key_G;
495             break;
496         case ID_DISASM_GOTOOFFSET:
497             ksResult=QKeySequence();
498             break;
499         case ID_DISASM_GOTOENTRYPOINT:
500             ksResult=QKeySequence();
501             break;
502         case ID_DISASM_HEXSIGNATURE:
503             ksResult=Qt::Key_S;
504             break;
505         case ID_DISASM_SIGNATURE:
506             ksResult=Qt::SHIFT+Qt::Key_G;
507             break;
508         case ID_DISASM_FIND:
509             ksResult=QKeySequence::Find;
510             break;
511         case ID_DISASM_FINDNEXT:
512             ksResult=QKeySequence::FindNext;
513             break;
514         case ID_DISASM_SELECTALL:
515             ksResult=QKeySequence::SelectAll;
516             break;
517         case ID_DISASM_COPYASHEX:
518             ksResult=QKeySequence::Copy;
519             break;
520         case ID_DISASM_COPYCURSORADDRESS:
521             ksResult=QKeySequence();
522             break;
523         case ID_DISASM_COPYCURSOROFFSET:
524             ksResult=QKeySequence();
525             break;
526         case ID_DISASM_HEX:
527             ksResult=QKeySequence();
528             break;
529         case ID_DEBUGGER_FILE_OPEN:
530         #ifdef Q_OS_WIN
531             ksResult=Qt::Key_F3;
532         #endif
533         #ifdef Q_OS_LINUX
534             ksResult=QKeySequence(); // TODO
535         #endif
536         #ifdef Q_OS_OSX
537             ksResult=Qt::CTRL+Qt::Key_O;
538         #endif
539             break;
540         case ID_DEBUGGER_FILE_CLOSE:
541             ksResult=QKeySequence();
542             break;
543         case ID_DEBUGGER_DEBUG_PAUSE:
544             ksResult=Qt::Key_F12;
545             break;
546         case ID_DEBUGGER_FILE_EXIT:
547             ksResult=Qt::ALT+Qt::Key_X;
548             break;
549         case ID_DEBUGGER_DEBUG_RUN:
550             ksResult=Qt::Key_F9;
551             break;
552         case ID_DEBUGGER_DEBUG_SETREMOVEBREAKPOINT:
553             ksResult=Qt::Key_F2;
554             break;
555         case ID_DEBUGGER_DEBUG_STEPINTO:
556             ksResult=Qt::Key_F7;
557             break;
558         case ID_DEBUGGER_DEBUG_STEPOVER:
559             ksResult=Qt::Key_F8;
560             break;
561         case ID_DEBUGGER_DEBUG_STOP:
562             ksResult=QKeySequence();
563             break;
564         case ID_DEBUGGER_DEBUG_RESTART:
565             ksResult=QKeySequence();
566             break;
567         case ID_DEBUGGER_FILE_ATTACH:
568         #ifdef Q_OS_WIN
569             ksResult=Qt::ALT+Qt::Key_A;
570         #endif
571         #ifdef Q_OS_LINUX
572             ksResult=QKeySequence(); // TODO
573         #endif
574         #ifdef Q_OS_OSX
575             ksResult=QKeySequence(); // TODO
576         #endif
577             break;
578         case ID_DEBUGGER_FILE_DETACH:
579         #ifdef Q_OS_WIN
580             ksResult=Qt::CTRL+Qt::ALT+Qt::Key_F2;
581         #endif
582         #ifdef Q_OS_LINUX
583             ksResult=QKeySequence(); // TODO
584         #endif
585         #ifdef Q_OS_OSX
586             ksResult=QKeySequence(); // TODO
587         #endif
588             break;
589         case ID_DEBUGGER_DISASM_DUMPTOFILE:
590             ksResult=QKeySequence();
591             break;
592         case ID_DEBUGGER_DISASM_GOTOADDRESS:
593             ksResult=QKeySequence();
594             break;
595         case ID_DEBUGGER_DISASM_HEXSIGNATURE:
596             ksResult=QKeySequence();
597             break;
598         case ID_DEBUGGER_DISASM_SIGNATURE:
599             ksResult=QKeySequence();
600             break;
601         case ID_DEBUGGER_DISASM_FIND:
602             ksResult=QKeySequence();
603             break;
604         case ID_DEBUGGER_DISASM_FINDNEXT:
605             ksResult=QKeySequence();
606             break;
607         case ID_DEBUGGER_DISASM_COPYASHEX:
608             ksResult=QKeySequence();
609             break;
610         case ID_DEBUGGER_DISASM_COPYCURSORADDRESS:
611             ksResult=QKeySequence();
612             break;
613         case ID_DEBUGGER_HEX_DUMPTOFILE:
614             ksResult=QKeySequence();
615             break;
616         case ID_DEBUGGER_HEX_GOTOADDRESS:
617             ksResult=QKeySequence();
618             break;
619         case ID_ARCHIVE_COPYFILENAME:
620             ksResult=QKeySequence::Copy;
621             break;
622         case ID_ARCHIVE_DUMPTOFILE:
623             ksResult=Qt::CTRL+Qt::Key_D;
624             break;
625         case ID_ARCHIVE_ENTROPY:
626             ksResult=QKeySequence();
627             break;
628         case ID_ARCHIVE_HASH:
629             ksResult=QKeySequence();
630             break;
631         case ID_ARCHIVE_HEX:
632             ksResult=QKeySequence();
633             break;
634         case ID_ARCHIVE_OPEN:
635             ksResult=QKeySequence();
636             break;
637         case ID_ARCHIVE_SCAN:
638             ksResult=QKeySequence();
639             break;
640         case ID_ARCHIVE_STRINGS:
641             ksResult=QKeySequence();
642             break;
643         case ID_TABLE_HEX:
644             ksResult=QKeySequence();
645             break;
646         case ID_TABLE_DISASM:
647             ksResult=QKeySequence();
648             break;
649         default:
650             ksResult=QKeySequence();
651     }
652 
653     return ksResult;
654 }
655 
groupIdToString(GROUPID groupId)656 QString XShortcuts::groupIdToString(GROUPID groupId)
657 {
658     QString sResult="";
659 
660     if      (groupId==GROUPID_ACTION)       sResult=tr("Action");
661     else if (groupId==GROUPID_FILE)         sResult=tr("File");
662     else if (groupId==GROUPID_VIEW)         sResult=tr("View");
663     else if (groupId==GROUPID_STRINGS)      sResult=tr("Strings");
664     else if (groupId==GROUPID_SIGNATURES)   sResult=tr("Signatures");
665     else if (groupId==GROUPID_HEX)          sResult=tr("Hex");
666     else if (groupId==GROUPID_DISASM)       sResult=tr("Disasm");
667     else if (groupId==GROUPID_DEBUG)        sResult=tr("Debug");
668     else if (groupId==GROUPID_DEBUGGER)     sResult=tr("Debugger");
669     else if (groupId==GROUPID_ARCHIVE)      sResult=tr("Archive");
670     else if (groupId==GROUPID_TABLE)        sResult=tr("Table");
671 
672     return sResult;
673 }
674 
getGroupEnd(GROUPID groupId)675 XShortcuts::ID XShortcuts::getGroupEnd(GROUPID groupId)
676 {
677     int nEnd=0;
678 
679     if(groupId==GROUPID_ACTION)         nEnd=ID_ACTION__END;
680     if(groupId==GROUPID_STRINGS)        nEnd=ID_STRINGS__END;
681     if(groupId==GROUPID_SIGNATURES)     nEnd=ID_SIGNATURES__END;
682     if(groupId==GROUPID_HEX)            nEnd=ID_HEX__END;
683     if(groupId==GROUPID_DISASM)         nEnd=ID_DISASM__END;
684     if(groupId==GROUPID_DEBUGGER)       nEnd=ID_DEBUGGER__END;
685     if(groupId==GROUPID_ARCHIVE)        nEnd=ID_ARCHIVE__END;
686     if(groupId==GROUPID_TABLE)          nEnd=ID_TABLE__END;
687 
688     return (ID)nEnd;
689 }
690 
getGroupId(XShortcuts::ID id)691 XShortcuts::GROUPID XShortcuts::getGroupId(XShortcuts::ID id)
692 {
693     qint32 nResult=id;
694 
695     nResult&=0xFF000000;
696 
697     nResult>>=24;
698 
699     return (GROUPID)nResult;
700 }
701 
getSubgroupId(ID id)702 XShortcuts::GROUPID XShortcuts::getSubgroupId(ID id)
703 {
704     GROUPID result=GROUPID_UNKNOWN;
705 
706     switch(id)
707     {
708         case ID_DEBUGGER_FILE_ATTACH:
709         case ID_DEBUGGER_FILE_CLOSE:
710         case ID_DEBUGGER_FILE_DETACH:
711         case ID_DEBUGGER_FILE_EXIT:
712         case ID_DEBUGGER_FILE_OPEN:
713             result=GROUPID_FILE;
714             break;
715         default:
716             result=GROUPID_UNKNOWN;
717     }
718 
719     return result;
720 }
721