-
Notifications
You must be signed in to change notification settings - Fork 3
/
ustrref.cpp
2097 lines (1911 loc) · 50.8 KB
/
ustrref.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
///////////////////////////////////////////////////////////////////////////////
//
// FileName : ustrref.cpp
// Version : 0.11
// Author : Luo Cong
// Date : 2004-07-27 (yyyy-mm-dd)
// Comment : 中文搜索引擎
//
///////////////////////////////////////////////////////////////////////////////
#include <windows.h>
#include <stdio.h>
#include "Plugin.h"
#include <string>
#include <vector>
using namespace std;
#define VERSIONY 2012
#define VERSIONM 4
#define VERSIOND 22
#define CHECKMAX 13
#define ABLEMAX 10
#define WSTRLEN 100
static HINSTANCE g_hInstance = NULL;
static HWND g_hWndMain = NULL;
static char g_szIniKey[] = "Restore UStrRef Window";
static char g_szPluginName[] = "中文搜索引擎";
static char g_szPassedTheEndOfFile[]= "Passed the end of file";
static char g_szTextToFind[TEXTLEN] = { 0 };
static int g_CurEIP_Item_Index = 0;
vector<string> g_strings;
static char g_szustrrefclass[32];
static t_table g_ustrreftbl;
static unsigned char g_chrRet[2];
typedef struct t_ustrref
{
ulong index; // ustrref index
ulong size; // Size of index, always 1 in our case
ulong type; // Type of entry, always 0
ulong addr; // Address of string
int iscureip; // Is Current EIP? 0: No, 1: Yes.
} t_ustrref;
BOOL APIENTRY DllMain(
HINSTANCE hModule,
DWORD dwReason,
LPVOID lpReserved
)
{
if (DLL_PROCESS_ATTACH == dwReason)
g_hInstance = hModule;
return TRUE;
}
int cdecl UStrRefGetText(
char *s,
char *mask,
int *select,
t_sortheader *ph,
int column
)
{
t_disasm da;
int n = 0;
t_memory *pmem;
ulong cmdsize;
uchar *pdecode;
ulong decodesize;
unsigned char cmd[MAXCMDSIZE];
t_ustrref *pb = (t_ustrref *)ph;
if (pb->iscureip) // Is Current EIP
*select = DRAW_HILITE;
else
*select = NULL;
switch (column)
{
case 0: // Address
n = sprintf((char *)s, "%08X", pb->addr);
break;
case 1: // Disassembly
pmem = Findmemory(pb->addr);
if (NULL == pmem)
{
*select = DRAW_GRAY;
return sprintf((char *)s, "???");
}
cmdsize = pmem->base + pmem->size - pb->addr;
if (cmdsize > MAXCMDSIZE)
cmdsize = MAXCMDSIZE;
if (
cmdsize != Readmemory(cmd, pb->addr, cmdsize, MM_RESTORE|MM_SILENT)
)
{
*select = DRAW_GRAY;
return sprintf((char *)s, "???");
}
pdecode = Finddecode(pb->addr, &decodesize);
if (decodesize < cmdsize)
pdecode = NULL;
Disasm(cmd, cmdsize, pb->addr, pdecode, &da, DISASM_CODE, 0);
n = sprintf((char *)s, "%s", da.result);
break;
case 2: // Text String
n = sprintf((char *)s, "%s", g_strings[pb->index].c_str());
break;
}
return n;
}
int FindNextAndScroll(HWND hWnd, int nStartPos)
{
int i;
int found = 0;
char *pdest = NULL;
string strinarray;
char texttofind[TEXTLEN];
strcpy(texttofind, g_szTextToFind);
for (i = nStartPos; i < g_strings.size(); ++i)
{
strinarray = g_strings[i].c_str();
pdest = strstr(
strlwr((char *)strinarray.c_str()),
strlwr(texttofind)
);
if (NULL != pdest)
{
Selectandscroll(&g_ustrreftbl, i, 2);
InvalidateRect(hWnd, NULL, FALSE);
found = 1;
break;
}
}
return found;
}
int FindPreviousAndScroll(HWND hWnd, int nStartPos)
{
int i;
int found = 0;
char *pdest = NULL;
string strinarray;
char texttofind[TEXTLEN];
strcpy(texttofind, g_szTextToFind);
for (i = nStartPos; i >= 0; --i)
{
strinarray = g_strings[i].c_str();
pdest = strstr(
strlwr((char *)strinarray.c_str()),
strlwr(texttofind)
);
if (NULL != pdest)
{
Selectandscroll(&g_ustrreftbl, i, 2);
InvalidateRect(hWnd, NULL, FALSE);
found = 1;
break;
}
}
return found;
}
void FindPrevious(HWND hWnd)
{
int found = 0;
t_ustrref *pb;
pb = (t_ustrref *)Getsortedbyselection(
&(g_ustrreftbl.data), g_ustrreftbl.data.selected);
if (NULL != pb && '\0' != g_szTextToFind[0])
{
found = FindPreviousAndScroll(hWnd, pb->index - 1);
// if not found, scroll to the last index and find again
if (!found)
{
Flash(g_szPassedTheEndOfFile);
FindPreviousAndScroll(hWnd, g_strings.size() - 1);
}
}
}
void FindNext(HWND hWnd)
{
int found = 0;
t_ustrref *pb;
pb = (t_ustrref *)Getsortedbyselection(
&(g_ustrreftbl.data), g_ustrreftbl.data.selected);
if (NULL != pb && '\0' != g_szTextToFind[0])
{
found = FindNextAndScroll(hWnd, pb->index + 1);
// if not found, scroll to index 0 and find again
if (!found)
{
Flash(g_szPassedTheEndOfFile);
FindNextAndScroll(hWnd, 0);
}
}
}
void Find(HWND hWnd)
{
int found = 0;
t_ustrref *pb;
char textnotfound[20 + TEXTLEN];
Gettext("Find", g_szTextToFind, 0, NM_COMMENT, FIXEDFONT);
pb = (t_ustrref *)Getsortedbyselection(
&(g_ustrreftbl.data), g_ustrreftbl.data.selected);
if (NULL != pb && '\0' != g_szTextToFind[0])
{
// find from current selected index
found = FindNextAndScroll(hWnd, pb->index);
// if not found, scroll to index 0 and find again
if (!found)
{
found = FindNextAndScroll(hWnd, 0);
if (!found)
{
sprintf(textnotfound, "\"%s\" not found!", g_szTextToFind);
MessageBox(
hWnd,
textnotfound,
g_szPluginName,
MB_OK | MB_ICONINFORMATION
);
}
}
}
}
LRESULT CALLBACK UStrRefWndProc(
HWND hWnd,
UINT msg,
WPARAM wParam,
LPARAM lParam
)
{
int i;
t_ustrref *pb;
HMENU menu;
switch (msg)
{
// Standard messages. You can process them, but - unless absolutely sure -
// always pass them to Tablefunction().
case WM_DESTROY:
case WM_MOUSEMOVE:
case WM_LBUTTONDOWN:
case WM_LBUTTONDBLCLK:
case WM_LBUTTONUP:
case WM_RBUTTONDOWN:
case WM_RBUTTONDBLCLK:
case WM_HSCROLL:
case WM_VSCROLL:
case WM_TIMER:
case WM_SYSKEYDOWN:
Tablefunction(&g_ustrreftbl, hWnd, msg, wParam, lParam);
break; // Pass message to DefMDIChildProc()
// Custom messages responsible for scrolling and selection. User-drawn
// windows must process them, standard OllyDbg windows without extra
// functionality pass them to Tablefunction().
case WM_USER_SCR:
case WM_USER_VABS:
case WM_USER_VREL:
case WM_USER_VBYTE:
case WM_USER_STS:
case WM_USER_CNTS:
case WM_USER_CHGS:
return Tablefunction(&g_ustrreftbl, hWnd, msg, wParam, lParam);
// WM_WINDOWPOSCHANGED is responsible for always-on-top MDI windows.
case WM_WINDOWPOSCHANGED:
return Tablefunction(&g_ustrreftbl, hWnd, msg, wParam, lParam);
case WM_USER_MENU:
menu = CreatePopupMenu();
// Find selected string. Any operations with string make sense only
// if at least one string exists and is selected. Note that sorted data
// has special sort index table which is updated only when necessary.
// Getsortedbyselection() does this; some other sorted data functions
// don't and you must call Sortsorteddata().
pb = (t_ustrref *)Getsortedbyselection(
&(g_ustrreftbl.data), g_ustrreftbl.data.selected);
if (NULL != menu && NULL != pb)
{
AppendMenu(menu, MF_STRING, 1, "&Follow\tEnter");
AppendMenu(menu, MF_SEPARATOR, NULL, NULL);
AppendMenu(menu, MF_STRING, 2, "F&ind\tCtrl+F or Insert");
AppendMenu(menu, MF_STRING, 3, "Find &Next\tb or n");
AppendMenu(menu, MF_STRING, 4, "Find &Previous\tz or p");
}
// Even when menu is NULL, call Tablefunction is still meaningful.
i = Tablefunction(
&g_ustrreftbl,
hWnd,
WM_USER_MENU,
0,
(LPARAM)menu
);
if (NULL != menu)
DestroyMenu(menu);
if (1 == i) // Follow address in Disassembler
{
Setcpu(
0,
pb->addr,
0,
0,
CPU_ASMHIST | CPU_ASMCENTER | CPU_ASMFOCUS
);
}
else if (2 == i) // Find
{
Find(hWnd);
}
else if (3 == i) // Find next
{
FindNext(hWnd);
}
return 0;
case WM_KEYDOWN:
// Processing of WM_KEYDOWN messages is - surprise, surprise - very
// similar to that of corresponding menu entries.
switch (wParam)
{
case VK_RETURN:
// Return key follows address in Disassembler.
pb = (t_ustrref *)Getsortedbyselection(
&(g_ustrreftbl.data), g_ustrreftbl.data.selected);
if (NULL != pb)
{
Setcpu(
0,
pb->addr,
0,
0,
CPU_ASMHIST | CPU_ASMCENTER | CPU_ASMFOCUS
);
}
break;
case VK_INSERT:
Find(hWnd);
break;
case 0x46: // Ctrl+'F' or Ctrl+'f'
if (GetKeyState(VK_CONTROL) < 0) // Ctrl key is pressing
Find(hWnd);
break;
case 0x42: // VK_B
case 0x4e: // VK_N
FindNext(hWnd);
break;
case 0x5a: // VK_Z
case 0x50: // VK_P
FindPrevious(hWnd);
break;
default:
// Add all this arrow, home and pageup functionality.
Tablefunction(&g_ustrreftbl, hWnd, msg, wParam, lParam);
break;
}
break;
case WM_USER_DBLCLK:
// Doubleclicking row follows address in Disassembler.
pb = (t_ustrref *)Getsortedbyselection(
&(g_ustrreftbl.data), g_ustrreftbl.data.selected);
if (NULL != pb)
{
Setcpu(
0,
pb->addr,
0,
0,
CPU_ASMHIST | CPU_ASMCENTER | CPU_ASMFOCUS
);
}
return 1; // Doubleclick processed
case WM_USER_CHALL:
case WM_USER_CHMEM:
// Something is changed, redraw window.
InvalidateRect(hWnd, NULL, FALSE);
return 0;
case WM_PAINT:
// Fill background of search window with default button colour.
// Necessary because Registerpluginclass() sets hbrBackground to NULL.
// Painting of all OllyDbg windows is done by Painttable(). Make custom
// drawing only if you have important reasons to do this.
Painttable(hWnd, &g_ustrreftbl, UStrRefGetText);
return 0;
default:
break;
}
return DefMDIChildProc(hWnd, msg, wParam, lParam);
}
void CreateUStrRefWindow(void)
{
if (0 == g_ustrreftbl.bar.nbar)
{
g_ustrreftbl.bar.name[0] = "地址";
g_ustrreftbl.bar.defdx[0] = 9;
g_ustrreftbl.bar.mode[0] = 0;
g_ustrreftbl.bar.name[1] = "反汇编";
g_ustrreftbl.bar.defdx[1] = 40;
g_ustrreftbl.bar.mode[1] = BAR_NOSORT;
g_ustrreftbl.bar.name[2] = "文本字符串";
g_ustrreftbl.bar.defdx[2] = 256;
g_ustrreftbl.bar.mode[2] = BAR_NOSORT;
g_ustrreftbl.bar.nbar = 3;
g_ustrreftbl.mode =
TABLE_COPYMENU |
TABLE_SORTMENU |
TABLE_APPMENU |
TABLE_SAVEPOS |
TABLE_ONTOP;
g_ustrreftbl.drawfunc = UStrRefGetText;
}
Quicktablewindow(
&g_ustrreftbl,
15,
3,
g_szustrrefclass,
g_szPluginName
);
}
int UStrRefSortFunc(t_ustrref *b1, t_ustrref *b2, int sort)
{
int i = 0;
if (1 == sort)
{
// Sort by address
if (b1->addr < b2->addr)
i = -1;
else if (b1->addr > b2->addr)
i = 1;
};
// If elements are equal or sorting is by the first column, sort by index.
if (0 == i)
{
if (b1->index < b2->index)
i = -1;
else if (b1->index > b2->index)
i = 1;
};
return i;
}
extc int _export cdecl ODBG_Plugindata(char shortname[32])
{
strcpy(shortname, g_szPluginName);
return PLUGIN_VERSION;
}
void UnicodeToGB2312(unsigned char* pOut,unsigned short uData)
{
WideCharToMultiByte(CP_ACP,NULL,(LPCWSTR)&uData,1,(LPSTR)pOut,sizeof(unsigned short),NULL,NULL);
return;
}
int IsSimplifiedCH2(unsigned short &dch)
{
int nRet;
unsigned char highbyte;
unsigned char lowbyte;
highbyte = dch & 0x00ff;
lowbyte = dch / 0x0100;
if (highbyte==0 || lowbyte==0)
return 0;
// 区名 码位范围 码位数 字符数 字符类型
// 双字节2区 B0A1—F7FE 6768 6763 汉字
if ((highbyte >= 0xb0 && highbyte <= 0xf7) && (lowbyte >= 0xa1 && lowbyte <= 0xfe))
return 1;
char GBt[3];
char GBs[3];
memset(GBt,0,3);
memcpy(GBt,&dch,2);
memset(GBs,0,3);
if (LCMapString(0x0804,LCMAP_SIMPLIFIED_CHINESE, GBt, 2, GBs, 2))
{
highbyte=GBs[0];
lowbyte=GBs[1];
if (highbyte==0 || lowbyte==0)
return 0;
if ((highbyte >= 0xb0 && highbyte <= 0xf7) && (lowbyte >= 0xa1 && lowbyte <= 0xfe))
{
memcpy(&dch,GBs,2);
return 1;
}
}
return 0;
}
int IsGraphicCH2(const unsigned short dch)
{
int nRet;
unsigned char highbyte;
unsigned char lowbyte;
highbyte = dch & 0x00ff;
lowbyte = dch / 0x0100;
// 区名 码位范围 码位数 字符数 字符类型
// 双字节1区 A1A1—A9FE 846 718 图形符号
if (
(highbyte >= 0xa1 && highbyte <= 0xa3) &&
(lowbyte >= 0xa1 && lowbyte <= 0xfe)
)
nRet = 1;
else
nRet = 0;
return nRet;
}
int IsStrW(DWORD StrBuf)
{
return 1;
}
int IsStrA(DWORD StrBuf)
{
return 1;
}
bool IsAlpha2(const unsigned short dch,unsigned char *g_chrRet)
{
g_chrRet[0]=0;
g_chrRet[1]=0;
UnicodeToGB2312(g_chrRet,dch);
if (!IsSimplifiedCH2(*(unsigned short *)g_chrRet) && !IsGraphicCH2(*(unsigned short *)g_chrRet))
return false;
if ((g_chrRet[0]==0 || g_chrRet[1]==0))
return false;
else
return true;
}
int IsAscII2(const unsigned short dch)
{
int nRet;
unsigned char highbyte;
unsigned char lowbyte;
highbyte = dch & 0x00ff;
lowbyte = dch / 0x0100;
if (highbyte>0x1B && highbyte<0x7F && lowbyte==0)
nRet = 1;
else
nRet = 0;
return nRet;
}
typedef int (__cdecl *RealStrToTextType) ( DWORD , DWORD , DWORD , DWORD );
RealStrToTextType RealStrToText;
bool isSimGra2(const unsigned short dch,unsigned char *g_chrRet)
{
g_chrRet[0]=0;
g_chrRet[1]=0;
memcpy(g_chrRet,&dch,2);
if (IsSimplifiedCH2(*(unsigned short *)g_chrRet) || IsGraphicCH2(*(unsigned short *)g_chrRet))
return true;
else
return false;
}
int StrToTextA(DWORD Str,DWORD StrLen,DWORD Dest,DWORD MaxLen)
{
string strAsc;
int i=0;
int len = 0;
int nInsert=0;
unsigned char g_chrRet[2];
string stringitem;
stringitem.erase();
unsigned char * buf=(unsigned char *)Str;
while (('\0' != *(buf + i)) && (i < WSTRLEN))
{
if ('\r' == *(buf + i))
{
stringitem += "\\r";
len += 2;
nInsert = 1;
}
else if ('\n' == *(buf + i))
{
stringitem += "\\n";
len += 2;
nInsert = 1;
}
else if ('\t' == *(buf + i))
{
stringitem += "\\t";
len += 2;
nInsert = 1;
}
else if (
'\0' != *(buf + i + 1) && (i + 1) < WSTRLEN &&
isSimGra2(*(unsigned short *)&buf[i],g_chrRet)
)
{
stringitem += g_chrRet[0];
++i;
++len;
stringitem += g_chrRet[1];
++len;
nInsert = 1;
}
else if (*(buf + i)>0x1B && *(buf + i)<0x7F)
{
stringitem += *(buf + i);
++len;
nInsert = 1;
}
else
{
nInsert = 0;
break;
}
if ((i + 1) == WSTRLEN)
break;
++i;
}
if (nInsert && stringitem.length()>1)
{
if (i >= WSTRLEN)
{
stringitem.replace(WSTRLEN - 4, 4, " ...");
len = WSTRLEN;
}
stringitem.replace(len, 1, "\0");
strAsc=stringitem;
}
else
{
char ascTemp[]={"ASCII"};
if (!memcmp((char*)(Dest-6),ascTemp,5))
strcpy((char*)(Dest-6),"");
else if (!memcmp((char*)(Dest-9),ascTemp,5))
strcpy((char*)(Dest-9),"");
return 0;
}
return RealStrToText((DWORD)strAsc.c_str(),(DWORD)strAsc.length(),Dest,MaxLen);
}
int StrToText(DWORD Str,DWORD StrLen,DWORD Dest,DWORD MaxLen)
{
string strAsc;
int i=0;
int len = 0;
int nInsert=0;
unsigned char g_chrRet[2];
string stringitem;
stringitem.erase();
unsigned char * buf=(unsigned char *)Str;
while (('\0' != *(buf + i)) || ('\0' != *(buf + i + 1)) && (i + 1 < WSTRLEN))
{
if (IsAlpha2(*(unsigned short *)&buf[i],g_chrRet))
{
stringitem += g_chrRet[0];
++i;
++len;
stringitem += g_chrRet[1];
++len;
nInsert = 1;
}
else if (IsAscII2(*(unsigned short *)&buf[i]))
{
stringitem += *(buf + i);
++i;
++len;
nInsert = 1;
}
else if ('\r' == *(buf + i) && (*(buf + i + 1) == '\0'))
{
stringitem += "\\r";
++i;
len += 2;
nInsert = 1;
}
else if ('\n' == *(buf + i) && (*(buf + i + 1) == '\0'))
{
stringitem += "\\n";
++i;
len += 2;
nInsert = 1;
}
else if ('\t' == *(buf + i) && (*(buf + i + 1) == '\0'))
{
stringitem += "\\t";
++i;
len += 2;
nInsert = 1;
}
else
{
nInsert = 0;
break;
}
if ((i + 1) == WSTRLEN)
break;
++i;
}
if (nInsert)
{
if (i >= WSTRLEN)
{
stringitem.replace(WSTRLEN - 4, 4, " ...");
len = WSTRLEN;
}
stringitem.replace(len, 1, "\0");
strAsc=stringitem;
}
else
{
strcpy((char*)(Dest-8),"");
return 0;
}
return RealStrToText((DWORD)strAsc.c_str(),(DWORD)strAsc.length(),Dest,MaxLen);
}
bool GetUnicode()
{
BYTE lpbyte[5] = {0xE8, 0xFB, 0x03, 0x00, 0x00};
DWORD dwCallRtl,lentemp;
dwCallRtl = 0x0047E21B;
if (*(BYTE*)dwCallRtl==0xFC)
{
WriteProcessMemory((HANDLE)-1, (PVOID)dwCallRtl, lpbyte+1, 1, &lentemp);
dwCallRtl = 0x004D54D0;
WriteProcessMemory((HANDLE)-1, (PVOID)dwCallRtl, lpbyte+2, 1, &lentemp);
}
else
return false;
dwCallRtl = 0x0047E162;
if (*(BYTE*)dwCallRtl==0xE8)
{
lentemp=(DWORD)IsStrW-dwCallRtl-5;
RtlCopyMemory(lpbyte+1, &lentemp, 4);
WriteProcessMemory((HANDLE)-1, (PVOID)dwCallRtl, lpbyte, 5, &lentemp);
}
else
return false;
dwCallRtl = 0x0047E183;
if (*(BYTE*)dwCallRtl==0xE8)
{
lentemp=(DWORD)IsStrW-dwCallRtl-5;
RtlCopyMemory(lpbyte+1, &lentemp, 4);
WriteProcessMemory((HANDLE)-1, (PVOID)dwCallRtl, lpbyte, 5, &lentemp);
}
else
return false;
dwCallRtl = 0x0047DDA3;
if (*(BYTE*)dwCallRtl==0xE8)
{
lentemp=(DWORD)IsStrA-dwCallRtl-5;
RtlCopyMemory(lpbyte+1, &lentemp, 4);
WriteProcessMemory((HANDLE)-1, (PVOID)dwCallRtl, lpbyte, 5, &lentemp);
}
else
return false;
dwCallRtl = 0x0047DDD2;
if (*(BYTE*)dwCallRtl==0xE8)
{
lentemp=(DWORD)IsStrA-dwCallRtl-5;
RtlCopyMemory(lpbyte+1, &lentemp, 4);
WriteProcessMemory((HANDLE)-1, (PVOID)dwCallRtl, lpbyte, 5, &lentemp);
}
else
return false;
dwCallRtl = 0x0047E21F;
if (*(BYTE*)dwCallRtl==0xE8)
{
RealStrToText=(RealStrToTextType)(dwCallRtl + *(PDWORD)(dwCallRtl+1) + 5);
lentemp=(DWORD)StrToText-dwCallRtl-5;
RtlCopyMemory(lpbyte+1, &lentemp, 4);
WriteProcessMemory((HANDLE)-1, (PVOID)dwCallRtl, lpbyte, 5, &lentemp);
}
else
return false;
dwCallRtl = 0x0047E01F;
if (*(BYTE*)dwCallRtl==0xE8)
{
lentemp=(DWORD)StrToTextA-dwCallRtl-5;
RtlCopyMemory(lpbyte+1, &lentemp, 4);
WriteProcessMemory((HANDLE)-1, (PVOID)dwCallRtl, lpbyte, 5, &lentemp);
}
else
return false;
dwCallRtl = 0x0047E109;
if (*(BYTE*)dwCallRtl==0xE8)
{
lentemp=(DWORD)StrToTextA-dwCallRtl-5;
RtlCopyMemory(lpbyte+1, &lentemp, 4);
WriteProcessMemory((HANDLE)-1, (PVOID)dwCallRtl, lpbyte, 5, &lentemp);
}
else
return false;
dwCallRtl = 0x0047DFCD;
if (*(BYTE*)dwCallRtl==0xE8)
{
lentemp=(DWORD)StrToTextA-dwCallRtl-5;
RtlCopyMemory(lpbyte+1, &lentemp, 4);
WriteProcessMemory((HANDLE)-1, (PVOID)dwCallRtl, lpbyte, 5, &lentemp);
}
else
return false;
}
extc int _export cdecl ODBG_Plugininit(
int ollydbgversion,
HWND hw,
ulong *features
)
{
int nRetCode;
int nRetResult = 0;
if (ollydbgversion < PLUGIN_VERSION)
{
nRetResult = -1;
goto Exit0;
}
g_hWndMain = hw;
nRetCode = Createsorteddata(
&(g_ustrreftbl.data),
"ustrref",
sizeof(t_ustrref),
10,
(SORTFUNC *)UStrRefSortFunc,
NULL
);
nRetCode = Registerpluginclass(
g_szustrrefclass,
NULL,
g_hInstance,
UStrRefWndProc
);
if (nRetCode < 0)
{
Destroysorteddata(&(g_ustrreftbl.data));
nRetResult = -1;
goto Exit0;
}
// Report plugin in the log window.
Addtolist(0, 0, "中文搜索引擎 v%d.%d.%d", VERSIONY, VERSIONM,VERSIOND);
Addtolist(0, -1, " Written by Luo Cong");
Addtolist(0, -1, " Compiled on " __DATE__ " " __TIME__);
if (
(0 != Plugingetvalue(VAL_RESTOREWINDOWPOS)) &&
(0 != Pluginreadintfromini(g_hInstance, g_szIniKey, 0))
)
{
CreateUStrRefWindow();
}
if (GetUnicode()==false)
{
MessageBox(0,"由于OD版本问题,实时UNICODE转化无法开启,你可以到 http://hi.baidu.com/chinahanwu 给我反馈错误","错误",MB_OK | MB_ICONINFORMATION);
}
Exit0:
return nRetResult;
}
extc int _export cdecl ODBG_Pluginclose(void)
{
Pluginwriteinttoini(
g_hInstance,
g_szIniKey,
NULL != g_ustrreftbl.hw
);
return 0;
}
extc void _export cdecl ODBG_Plugindestroy(void)
{
Unregisterpluginclass(g_szustrrefclass);
Destroysorteddata(&(g_ustrreftbl.data));
}
extc int _export cdecl ODBG_Pluginmenu(int origin, char data[4096], void *item)
{
t_dump *pd;
switch (origin)
{
case PM_MAIN:
strcpy(data, "0 &1 搜索 ASCII|1 &2 搜索 UNICODE|2 &3 智能搜索|3 &4 帮助|4 &5 关于");
return 1;
case PM_DISASM: // Popup menu in Disassembler
pd = (t_dump *)item;
if (NULL == pd || 0 == pd->size) // Window empty, don't add
return 0;
// Add item "中文搜索引擎"
// if some part of Disassembler is selected
if (pd->sel1 > pd->sel0)
{
sprintf(
data,
"0 &中文搜索引擎{"
"0 &1 搜索 ASCII|1 &2 搜索 UNICODE|2 &3 智能搜索|3 &4 帮助|4 &5 关于"
"}"
);
}
return 1;
}
return 0;
}
int IsPrintAble(const unsigned char ch)
{
int nRet;
if (ch >= 0x20 && ch < 0x7f)
nRet = 1;
else if (0xff == ch)
nRet = 0;
else if (0x80 == (ch & 0x80))
nRet = 1;
else
nRet = 0;
return nRet;
}
int IsSimplifiedCH(unsigned short &dch)
{
int nRet;
unsigned char highbyte;
unsigned char lowbyte;
highbyte = dch & 0x00ff;
lowbyte = dch / 0x0100;
if (highbyte==0 || lowbyte==0)
return 0;