1 Star 1 Fork 5

yenmuse/TSPlug

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
TSMemoryAPI.cpp 100.65 KB
一键复制 编辑 原始数据 按行查看 历史
GJX 提交于 2017-08-10 10:29 . 天使插件
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270
/*
本源码由TC简单软件科技有限公司开源,功能可以自由修改、发布、
长沙简单软件科技有限公司对于源码不做后期维护,,请大家在使用过程中遵循开源协议
*/
#include "StdAfx.h"
#include "TSMemoryAPI.h"
#include <Tlhelp32.h>
#include <psapi.h>
#include "TSRuntime.h"
#include "TSMyUser32DllFuntion.h"
#include "TSMyKernel32DllFuntion.h"
//#include "TSVIPHookFuntion.h"
#pragma comment ( lib, "psapi.lib" )
extern myOpenProcess my_OpenProcess;
extern myGetWindowThreadProcessId my_GetWindowThreadProcessId;
extern myReadProcessMemory my_ReadProcessMemory;
extern myWriteProcessMemory my_WriteProcessMemory;
extern myTerminateProcess my_TerminateProcess;
extern myVirtualProtect my_VirtualProtect;
extern myVirtualProtectEx my_VirtualProtectEx;
extern myCreateRemoteThread my_CreateRemoteThread;
extern myZwOpenProcess my_ZwOpenProcess;
typedef LONG (WINAPI *PROCNTQSIP)(HANDLE,UINT,PVOID,ULONG,PULONG);
PROCNTQSIP NtQueryInformationProcess;
//NtReadVirtualMemory(
// IN HANDLE ProcessHandle,
// IN PVOID BaseAddress,
// OUT PVOID Buffer,
// IN ULONG NumberOfBytesToRead,
// OUT PULONG NumberOfBytesReaded OPTIONAL );
extern DWORD Ntdll_ProtectVirtual;
extern DWORD Ntdll_ProtectVirtualEax;
extern DWORD ZwWriteVirtualMemoryRet;
extern DWORD ZwWriteVirtualMemoryEax;
DWORD GetWindowThreadProcessIdRet=0;
__declspec(naked) DWORD WINAPI My_GetWindowThreadProcessId( HWND hWnd, LPDWORD lpdwProcessId )
{
_asm
{
mov edi,edi
push ebp
mov ebp,esp
jmp GetWindowThreadProcessIdRet;
}
}
DWORD ZwOpenProcessRet=0;
DWORD ZwOpenProcessEax=0;
__declspec(naked) NTSTATUS WINAPI My_ZwOpenProcess(
__out PHANDLE ProcessHandle,
__in ACCESS_MASK DesiredAccess,
__in POBJECT_ATTRIBUTES ObjectAttributes,
__in_opt PCLIENT_ID ClientId
)
{
_asm
{
//MOV EAX,0x23 //win7
mov eax,ZwOpenProcessEax;
jmp ZwOpenProcessRet;
}
}
HANDLE My_OpenProcess(int proid)
{
HANDLE ProcessHandle=(HANDLE)0;
OBJECT_ATTRIBUTES ObjectAttribute={sizeof(OBJECT_ATTRIBUTES), 0,NULL,NULL};
ObjectAttribute.Attributes=0;
CLIENT_ID ClientIds;
ClientIds.UniqueProcess=(HANDLE)proid;
ClientIds.UniqueThread=(HANDLE)0;
My_ZwOpenProcess(&ProcessHandle,PROCESS_ALL_ACCESS,&ObjectAttribute,&ClientIds);
ProcessHandle;
return ProcessHandle;
}
int GetProcessNumber()//获取CPU个数 ,CPU核数决定线程个数
{
SYSTEM_INFO info;
GetSystemInfo(&info);
return (int)info.dwNumberOfProcessors;
}
TSMemoryAPI::TSMemoryAPI(void)
{
nPid=0;
retstringlen=0;
asmcodearry.clear();
memset(Asmcalladdr,0,MAX_PATH);
allocatememory=NULL;
int sysvion=TSRuntime::InitialWindowsVersion();
if(GetWindowThreadProcessIdRet==0)
{
DWORD addr=(DWORD)GetProcAddress(GetModuleHandle(L"user32.dll"),"GetWindowThreadProcessId");
GetWindowThreadProcessIdRet=addr+5;
}
if(ZwWriteVirtualMemoryRet==0)
{
DWORD addr=(DWORD)GetProcAddress(GetModuleHandle(L"ntdll.dll"),"ZwWriteVirtualMemory");
ZwWriteVirtualMemoryRet=addr+5;
if(sysvion==4&&TSRuntime::IsWin7X64)//win7X64
ZwWriteVirtualMemoryEax=0x37;
else if(sysvion==4)//win7x86
ZwWriteVirtualMemoryEax=0x18F;
else if(sysvion==1)//WINXP
ZwWriteVirtualMemoryEax=0x115;
else if(sysvion==2)//WIN2003
ZwWriteVirtualMemoryEax=0x11f;
else if(sysvion==5&&TSRuntime::IsWin8X64)
ZwWriteVirtualMemoryEax=0x38;
else if(sysvion==5)//win8X86
ZwWriteVirtualMemoryEax=0x2;
}
if(Ntdll_ProtectVirtual==0)
{
DWORD addr=(DWORD)GetProcAddress(GetModuleHandle(L"ntdll.dll"),"ZwProtectVirtualMemory");
Ntdll_ProtectVirtual=addr+5;
if(sysvion==4&&TSRuntime::IsWin7X64)//win7X64
Ntdll_ProtectVirtualEax=0x4d;
else if(sysvion==4)//win7x86
Ntdll_ProtectVirtualEax=0xd7;
else if(sysvion==1)//WINXP
Ntdll_ProtectVirtualEax=0x89;
else if(sysvion==2)//WIN2003
Ntdll_ProtectVirtualEax=0x8f;
else if(sysvion==5&&TSRuntime::IsWin8X64)
Ntdll_ProtectVirtualEax=0x4e;
else if(sysvion==5)//win8X86
Ntdll_ProtectVirtualEax=0xC3;
}
if(ZwOpenProcessRet==0)
{
DWORD addr=(DWORD)GetProcAddress(GetModuleHandle(L"ntdll.dll"),"ZwOpenProcess");
ZwOpenProcessRet=addr+5;
if(sysvion==4&&TSRuntime::IsWin7X64)//win7X64
ZwOpenProcessEax=0x23;
else if(sysvion==4)//win7x86
ZwOpenProcessEax=0xBe;
else if(sysvion==1)//WINXP
ZwOpenProcessEax=0x7a;
else if(sysvion==2)//WIN2003
ZwOpenProcessEax=0X80;
else if(sysvion==5&&TSRuntime::IsWin8X64)
ZwOpenProcessEax=0X24;
else if(sysvion==5)//win8X86
ZwOpenProcessEax=0XDD;
}
// m_mutex=mm_mutex;
}
TSMemoryAPI::~TSMemoryAPI(void)
{
}
void FindDataThread(void *para)
{
PFindDataInfo info=(PFindDataInfo)para;
BYTE buffData[4096]={0};
int retstrlen=0;
//DWORD count=0;
DWORD dwRead=0;
DWORD ibegin=0;
if(info->FindDataType==FINDDATATYPE_FINDFLOATEX) //FindFloatEx
{
for(int n=0;n<info->dwncount;n++)
{
EnterCriticalSection(&info->m_mutex);//临界区保护多线程
for(int k=0;k<info->dwncount;k++)
{
if(info->bfindindex[k]==true)
n=k;
else
{
info->bfindindex[k]=true;
break;
}
}
LeaveCriticalSection(&info->m_mutex);//临界区保护多线程
int size=info->dwend[n]-info->dwbegin[n];
if(size<=4096)
{
ibegin=info->dwbegin[n];
::memset(buffData,0,size);
if(ReadProcessMemory(info->hprocess,LPVOID(info->dwbegin[n]),buffData,size,&dwRead))
{
int i=0;
for(;i<(int)dwRead;i++)
{
float *float_value=(float *)&buffData[i];
if(*float_value>=info->float_value_min&&*float_value<=info->float_value_max)
{
EnterCriticalSection(&info->m_mutex);//临界区保护多线程对同一个字符串操作
if(info->count<=20000) //记录找到地址的上限为20000,防止溢出
{
wchar_t inx[10]={0};
if(retstrlen==0)
retstrlen=wcslen(info->retstr);
if(retstrlen==0)
swprintf(inx,L"%X",(ibegin+i));
else
swprintf(inx,L"|%X",(ibegin+i));
wcscat(info->retstr,inx);
}
else
{
LeaveCriticalSection(&info->m_mutex);
return;
}
info->count++;
LeaveCriticalSection(&info->m_mutex);
}
}
}
}
else
{
ibegin=info->dwbegin[n];
int sizen=4096;
while(ibegin<info->dwend[n]&&info->dwend[n]>0)
{
if(ReadProcessMemory(info->hprocess,LPVOID(ibegin),buffData,sizen,&dwRead))
{
int i=0;
for(;i<(int)dwRead;i++)
{
float *float_value=(float *)&buffData[i];
if(*float_value>=info->float_value_min&&*float_value<=info->float_value_max)
{
EnterCriticalSection(&info->m_mutex);//临界区保护多线程对同一个字符串操作
if(info->count<=20000) //记录找到地址的上限为20000,防止溢出
{
wchar_t inx[10]={0};
if(retstrlen==0)
retstrlen=wcslen(info->retstr);
if(retstrlen==0)
swprintf(inx,L"%X",(ibegin+i));
else
swprintf(inx,L"|%X",(ibegin+i));
wcscat(info->retstr,inx);
}
else
{
LeaveCriticalSection(&info->m_mutex);
return;
}
info->count++;
LeaveCriticalSection(&info->m_mutex);
}
}
}
if(info->dwend[n]>=ibegin+4096)
ibegin=ibegin+4096;
else
{
sizen=info->dwend[n]-ibegin;
ibegin=ibegin+4096;
::memset(buffData,0,sizen);
}
}
}
}
}
else if(info->FindDataType==FINDDATATYPE_FINDDOUBLEEX) //FindDoubleEx
{
for(int n=0;n<info->dwncount;n++)
{
EnterCriticalSection(&info->m_mutex);//临界区保护多线程
for(int k=0;k<info->dwncount;k++)
{
if(info->bfindindex[k]==true)
n=k;
else
{
info->bfindindex[k]=true;
break;
}
}
LeaveCriticalSection(&info->m_mutex);//临界区保护多线程
int size=info->dwend[n]-info->dwbegin[n];
if(size<=4096)
{
ibegin=info->dwbegin[n];
::memset(buffData,0,size);
if(ReadProcessMemory(info->hprocess,LPVOID(ibegin),buffData,size,&dwRead))
{
int i=0;
for(;i<(int)dwRead;i++)
{
double *double_value=(double *)&buffData[i];
if(*double_value>=info->double_value_min&&*double_value<=info->double_value_max)
{
EnterCriticalSection(&info->m_mutex);//临界区保护多线程对同一个字符串操作
if(info->count<=20000) //记录找到地址的上限为20000,防止溢出
{
wchar_t inx[10]={0};
if(retstrlen==0)
retstrlen=wcslen(info->retstr);
if(retstrlen==0)
swprintf(inx,L"%X",(ibegin+i));
else
swprintf(inx,L"|%X",(ibegin+i));
wcscat(info->retstr,inx);
//swprintf(info->retstr,L"%s|%X",info->retstr,(ibegin+i));
}
else
{
LeaveCriticalSection(&info->m_mutex);
return;
}
info->count++;
LeaveCriticalSection(&info->m_mutex);
}
}
}
}
else
{
ibegin=info->dwbegin[n];
int sizen=4096;
while(ibegin<info->dwend[n]&&info->dwend[n]>0)
{
if(ReadProcessMemory(info->hprocess,LPVOID(ibegin),buffData,sizen,&dwRead))
{
int i=0;
for(;i<(int)dwRead;i++)
{
double *double_value=(double *)&buffData[i];
if(*double_value>=info->double_value_min&&*double_value<=info->double_value_max)
{
EnterCriticalSection(&info->m_mutex);//临界区保护多线程对同一个字符串操作
if(info->count<=20000) //记录找到地址的上限为20000,防止溢出
{
wchar_t inx[10]={0};
if(retstrlen==0)
retstrlen=wcslen(info->retstr);
if(retstrlen==0)
swprintf(inx,L"%X",(ibegin+i));
else
swprintf(inx,L"|%X",(ibegin+i));
wcscat(info->retstr,inx);
//swprintf(info->retstr,L"%s|%X",info->retstr,(ibegin+i));
}
else
{
LeaveCriticalSection(&info->m_mutex);
return;
}
info->count++;
LeaveCriticalSection(&info->m_mutex);
}
}
}
if(info->dwend[n]>=ibegin+4096)
ibegin=ibegin+4096;
else
{
sizen=info->dwend[n]-ibegin;
ibegin=ibegin+4096;
::memset(buffData,0,sizen);
}
}
}
}
}
else if(info->FindDataType==FINDDATATYPE_FINDINTEX)//FindIntEx
{
for(int n=0;n<info->dwncount;n++)
{
EnterCriticalSection(&info->m_mutex);//临界区保护多线程
for(int k=0;k<info->dwncount;k++)
{
if(info->bfindindex[k]==true)
n=k;
else
{
info->bfindindex[k]=true;
break;
}
}
LeaveCriticalSection(&info->m_mutex);//临界区保护多线程
int size=info->dwend[n]-info->dwbegin[n];
if(size<=4096)
{
ibegin=info->dwbegin[n];
::memset(buffData,0,size);
if(ReadProcessMemory(info->hprocess,LPVOID(ibegin),buffData,size,&dwRead))
{
int i=0;
for(;i<(int)dwRead;i++)
{
if(info->FindIntType==0)//0 : 32位
{
int *value=(int *)&buffData[i];
if(*value>=info->int_value_min&&*value<=info->int_value_max)
{
EnterCriticalSection(&info->m_mutex);//临界区保护多线程对同一个字符串操作
if(info->count<=20000) //记录找到地址的上限为20000,防止溢出
{
wchar_t inx[10]={0};
if(retstrlen==0)
retstrlen=wcslen(info->retstr);
if(retstrlen==0)
swprintf(inx,L"%X",(ibegin+i));
else
swprintf(inx,L"|%X",(ibegin+i));
wcscat(info->retstr,inx);
//swprintf(info->retstr,L"%s|%X",info->retstr,(ibegin+i));
}
else
{
LeaveCriticalSection(&info->m_mutex);
return;
}
info->count++;
LeaveCriticalSection(&info->m_mutex);
}
}
else if(info->FindIntType==1) //1 : 16 位
{
short *value=(short *)&buffData[i];
if(*value>=info->int_value_min&&*value<=info->int_value_max)
{
EnterCriticalSection(&info->m_mutex);//临界区保护多线程对同一个字符串操作
if(info->count<=20000) //记录找到地址的上限为20000,防止溢出
{
wchar_t inx[10]={0};
if(retstrlen==0)
retstrlen=wcslen(info->retstr);
if(retstrlen==0)
swprintf(inx,L"%X",(ibegin+i));
else
swprintf(inx,L"|%X",(ibegin+i));
wcscat(info->retstr,inx);
//swprintf(info->retstr,L"%s|%X",info->retstr,(ibegin+i));
}
else
{
LeaveCriticalSection(&info->m_mutex);
return;
}
info->count++;
LeaveCriticalSection(&info->m_mutex);
}
}
else if(info->FindIntType==2)//2 : 8位
{
if(buffData[i]>=info->int_value_min&&buffData[i]<=info->int_value_max)
{
EnterCriticalSection(&info->m_mutex);//临界区保护多线程对同一个字符串操作
if(info->count<=20000) //记录找到地址的上限为20000,防止溢出
{
wchar_t inx[10]={0};
if(retstrlen==0)
retstrlen=wcslen(info->retstr);
if(retstrlen==0)
swprintf(inx,L"%X",(ibegin+i));
else
swprintf(inx,L"|%X",(ibegin+i));
wcscat(info->retstr,inx);
//swprintf(info->retstr,L"%s|%X",info->retstr,(ibegin+i));
}
else
{
LeaveCriticalSection(&info->m_mutex);
return;
}
info->count++;
LeaveCriticalSection(&info->m_mutex);
}
}
}
}
}
else
{
ibegin=info->dwbegin[n];
int sizen=4096;
while(ibegin<info->dwend[n]&&info->dwend[n]>0)
{
if(ReadProcessMemory(info->hprocess,LPVOID(ibegin),buffData,sizen,&dwRead))
{
int i=0;
for(;i<(int)dwRead;i++)
{
if(info->FindIntType==0)//0 : 32位
{
int *value=(int *)&buffData[i];
if(*value>=info->int_value_min&&*value<=info->int_value_max)
{
EnterCriticalSection(&info->m_mutex);//临界区保护多线程对同一个字符串操作
if(info->count<=20000) //记录找到地址的上限为20000,防止溢出
{
wchar_t inx[10]={0};
if(retstrlen==0)
retstrlen=wcslen(info->retstr);
if(retstrlen==0)
swprintf(inx,L"%X",(ibegin+i));
else
swprintf(inx,L"|%X",(ibegin+i));
wcscat(info->retstr,inx);
//swprintf(info->retstr,L"%s|%X",info->retstr,(ibegin+i));
}
else
{
LeaveCriticalSection(&info->m_mutex);
return;
}
info->count++;
LeaveCriticalSection(&info->m_mutex);
}
}
else if(info->FindIntType==1) //1 : 16 位
{
short *value=(short *)&buffData[i];
if(*value>=info->int_value_min&&*value<=info->int_value_max)
{
EnterCriticalSection(&info->m_mutex);//临界区保护多线程对同一个字符串操作
if(info->count<=20000) //记录找到地址的上限为20000,防止溢出
{
wchar_t inx[10]={0};
if(retstrlen==0)
retstrlen=wcslen(info->retstr);
if(retstrlen==0)
swprintf(inx,L"%X",(ibegin+i));
else
swprintf(inx,L"|%X",(ibegin+i));
wcscat(info->retstr,inx);
//swprintf(info->retstr,L"%s|%X",info->retstr,(ibegin+i));
}
else
{
LeaveCriticalSection(&info->m_mutex);
return;
}
info->count++;
LeaveCriticalSection(&info->m_mutex);
}
}
else if(info->FindIntType==2)//2 : 8位
{
if(buffData[i]>=info->int_value_min&&buffData[i]<=info->int_value_max)
{
EnterCriticalSection(&info->m_mutex);//临界区保护多线程对同一个字符串操作
if(info->count<=20000) //记录找到地址的上限为20000,防止溢出
{
wchar_t inx[10]={0};
if(retstrlen==0)
retstrlen=wcslen(info->retstr);
if(retstrlen==0)
swprintf(inx,L"%X",(ibegin+i));
else
swprintf(inx,L"|%X",(ibegin+i));
wcscat(info->retstr,inx);
//swprintf(info->retstr,L"%s|%X",info->retstr,(ibegin+i));
}
else
{
LeaveCriticalSection(&info->m_mutex);
return;
}
info->count++;
LeaveCriticalSection(&info->m_mutex);
}
}
}
}
if(info->dwend[n]>=ibegin+4096)
ibegin=ibegin+4096;
else
{
sizen=info->dwend[n]-ibegin;
ibegin=ibegin+4096;
::memset(buffData,0,sizen);
}
}
}
}
}
else if(info->FindDataType==FINDDATATYPE_FINDDATAEX)
{
int nindex=0;
for(int n=0;n<info->dwncount;n++)
{
EnterCriticalSection(&info->m_mutex);//临界区保护多线程
for(int k=0;k<info->dwncount;k++)
{
if(info->bfindindex[k]==true)
n=k;
else
{
info->bfindindex[k]=true;
break;
}
}
LeaveCriticalSection(&info->m_mutex);//临界区保护多线程
int size=info->dwend[n]-info->dwbegin[n];
if(size<=4096)
{
ibegin=info->dwbegin[n];
::memset(buffData,0,size);
if(ReadProcessMemory(info->hprocess,LPVOID(ibegin),buffData,size,&dwRead))
{
int i=0;
for(;i<(int)dwRead;i++)
{
if(buffData[i]==info->Finddata[nindex]||info->Finddata[nindex]==256)// unknow=256;//标记??模糊查询
{
if(info->FindIntType==(nindex+1)) //匹配成功
{
EnterCriticalSection(&info->m_mutex);//临界区保护多线程对同一个字符串操作
if(info->count<=20000) //记录找到地址的上限为20000,防止溢出
{
wchar_t inx[10]={0};
if(retstrlen==0)
retstrlen=wcslen(info->retstr);
if(retstrlen==0)
swprintf(inx,L"%X",(ibegin+i)-nindex);
else
swprintf(inx,L"|%X",(ibegin+i)-nindex);
wcscat(info->retstr,inx);
//swprintf(info->retstr,L"%s|%X",info->retstr,(ibegin+i)-nindex);
}
else
{
LeaveCriticalSection(&info->m_mutex);
return;
}
info->count++;
nindex=0;
LeaveCriticalSection(&info->m_mutex);
}
nindex++;
}
else
nindex=0;
}
}
}
else
{
ibegin=info->dwbegin[n];
int sizen=4096;
while(ibegin<info->dwend[n]&&info->dwend[n]>0)
{
if(ReadProcessMemory(info->hprocess,LPVOID(ibegin),buffData,sizen,&dwRead))
{
int i=0;
for(;i<(int)dwRead;i++)
{
if(buffData[i]==info->Finddata[nindex]||info->Finddata[nindex]==256)// unknow=256;//标记??模糊查询
{
if(info->FindIntType==(nindex+1)) //匹配成功
{
EnterCriticalSection(&info->m_mutex);//临界区保护多线程对同一个字符串操作
if(info->count<=20000) //记录找到地址的上限为20000,防止溢出
{
wchar_t inx[10]={0};
if(retstrlen==0)
retstrlen=wcslen(info->retstr);
if(retstrlen==0)
swprintf(inx,L"%X",(ibegin+i)-nindex);
else
swprintf(inx,L"|%X",(ibegin+i)-nindex);
wcscat(info->retstr,inx);
//swprintf(info->retstr,L"%s|%X",info->retstr,(ibegin+i)-nindex);
}
else
{
LeaveCriticalSection(&info->m_mutex);
return;
}
info->count++;
nindex=0;
LeaveCriticalSection(&info->m_mutex);
}
nindex++;
}
else
nindex=0;
}
}
if(info->dwend[n]>=ibegin+4096)
ibegin=ibegin+4096;
else
{
sizen=info->dwend[n]-ibegin;
ibegin=ibegin+4096;
::memset(buffData,0,sizen);
}
}
}
}
}
else if(info->FindDataType==FINDDATATYPE_FINDSTRINGEX)
{
int nindex=0;
//////////////////0:ASCCII编码查找 1:Unicode编码查找//////////////////////////////
if(info->FindIntType == 1)
{
USES_CONVERSION;
int len=wcslen(info->Findstring);
char chstr[MAX_PATH*2]={0};
strcpy(chstr,W2A(info->Findstring));
len=strlen(chstr);;
for(int n=0;n<info->dwncount;n++)
{
EnterCriticalSection(&info->m_mutex);//临界区保护多线程
for(int k=0;k<info->dwncount;k++)
{
if(info->bfindindex[k]==true)
n=k;
else
{
info->bfindindex[k]=true;
break;
}
}
LeaveCriticalSection(&info->m_mutex);//临界区保护多线程
int size=info->dwend[n]-info->dwbegin[n];
if(size<=4096)
{
ibegin=info->dwbegin[n];
::memset(buffData,0,size);
if(ReadProcessMemory(info->hprocess,LPVOID(ibegin),buffData,size,&dwRead))
{
int i=0;
for(;i<(int)dwRead;i++)
{
if(buffData[i]==chstr[nindex])
{
if(len==(nindex+1)) //匹配成功
{
EnterCriticalSection(&info->m_mutex);//临界区保护多线程对同一个字符串操作
if(info->count<=20000) //记录找到地址的上限为20000,防止溢出
{
wchar_t inx[10]={0};
if(retstrlen==0)
retstrlen=wcslen(info->retstr);
if(retstrlen==0)
swprintf(inx,L"%X",(ibegin+i)-nindex);
else
swprintf(inx,L"|%X",(ibegin+i)-nindex);
wcscat(info->retstr,inx);
//swprintf(info->retstr,L"%s|%X",info->retstr,(ibegin+i)-nindex);
}
else
{
LeaveCriticalSection(&info->m_mutex);
return;
}
info->count++;
nindex=0;
LeaveCriticalSection(&info->m_mutex);
}
nindex++;
}
else
nindex=0;
}
}
}
else
{
ibegin=info->dwbegin[n];
int sizen=4096;
while(ibegin<info->dwbegin[n]&&info->dwbegin[n]>0)
{
if(ReadProcessMemory(info->hprocess,LPVOID(ibegin),buffData,sizen,&dwRead))
{
int i=0;
for(;i<(int)dwRead;i++)
{
if(buffData[i]==chstr[nindex])
{
if(len==(nindex+1)) //匹配成功
{
EnterCriticalSection(&info->m_mutex);//临界区保护多线程对同一个字符串操作
if(info->count<=20000) //记录找到地址的上限为20000,防止溢出
{
wchar_t inx[10]={0};
if(retstrlen==0)
retstrlen=wcslen(info->retstr);
if(retstrlen==0)
swprintf(inx,L"%X",(ibegin+i)-nindex);
else
swprintf(inx,L"|%X",(ibegin+i)-nindex);
wcscat(info->retstr,inx);
//swprintf(info->retstr,L"%s|%X",info->retstr,(ibegin+i)-nindex);
}
else
{
LeaveCriticalSection(&info->m_mutex);
return;
}
info->count++;
nindex=0;
LeaveCriticalSection(&info->m_mutex);
}
nindex++;
}
else
nindex=0;
}
}
if(info->dwbegin[n]>=ibegin+4096)
ibegin=ibegin+4096;
else
{
sizen=info->dwbegin[n]-ibegin;
ibegin=ibegin+4096;
::memset(buffData,0,sizen);
}
}
}
}
}
else if(info->FindIntType==0)
{
int len=wcslen(info->Findstring);
for(int n=0;n<info->dwncount;n++)
{
EnterCriticalSection(&info->m_mutex);//临界区保护多线程
for(int k=0;k<info->dwncount;k++)
{
if(info->bfindindex[k]==true)
n=k;
else
{
info->bfindindex[k]=true;
break;
}
}
LeaveCriticalSection(&info->m_mutex);//临界区保护多线程
int size=info->dwend[n]-info->dwbegin[n];
if(size<=4096)
{
ibegin=info->dwbegin[n];
::memset(buffData,0,size);
if(ReadProcessMemory(info->hprocess,LPVOID(ibegin),buffData,size,&dwRead))
{
int i=0;
for(;i<(int)dwRead;i++)
{
if(buffData[i]==info->Findstring[nindex])
{
if(len==(nindex+1)) //匹配成功
{
EnterCriticalSection(&info->m_mutex);//临界区保护多线程对同一个字符串操作
if(info->count<=20000) //记录找到地址的上限为20000,防止溢出
{
wchar_t inx[10]={0};
if(retstrlen==0)
retstrlen=wcslen(info->retstr);
if(retstrlen==0)
swprintf(inx,L"%X",ibegin+(i-nindex)*2);
else
swprintf(inx,L"|%X",ibegin+(i-nindex)*2);
wcscat(info->retstr,inx);
//swprintf(info->retstr,L"%s|%X",info->retstr,ibegin+(i-nindex)*2);
}
else
{
LeaveCriticalSection(&info->m_mutex);
return;
}
info->count++;
nindex=0;
LeaveCriticalSection(&info->m_mutex);
}
nindex++;
}
else
nindex=0;
}
}
}
else
{
ibegin=info->dwbegin[n];
int sizen=4096;
while(ibegin<info->dwend[n]&&info->dwend[n]>0)
{
if(ReadProcessMemory(info->hprocess,LPVOID(ibegin),buffData,sizen,&dwRead))
{
int i=0;
for(;i<(int)dwRead;i++)
{
if(buffData[i]==info->Findstring[nindex])
{
if(len==(nindex+1)) //匹配成功
{
EnterCriticalSection(&info->m_mutex);//临界区保护多线程对同一个字符串操作
if(info->count<=20000) //记录找到地址的上限为20000,防止溢出
{
wchar_t inx[10]={0};
if(retstrlen==0)
retstrlen=wcslen(info->retstr);
if(retstrlen==0)
swprintf(inx,L"%X",ibegin+(i-nindex)*2);
else
swprintf(inx,L"|%X",ibegin+(i-nindex)*2);
wcscat(info->retstr,inx);
//swprintf(info->retstr,L"%s|%X",info->retstr,ibegin+(i-nindex)*2);
}
else
{
LeaveCriticalSection(&info->m_mutex);
return;
}
info->count++;
nindex=0;
LeaveCriticalSection(&info->m_mutex);
}
nindex++;
}
else
nindex=0;
}
}
if(info->dwend[n]>=ibegin+4096)
ibegin=ibegin+4096;
else
{
sizen=info->dwend[n]-ibegin;
ibegin=ibegin+4096;
::memset(buffData,0,sizen);
}
}
}
}
}
}
}
bool TSMemoryAPI::TSFindInt(LONG hwnd,wchar_t * addr_range,wchar_t *retstr,LONG int_value_min, LONG int_value_max,LONG type,bool threadtype)
{
bool bret=false;
LONG ibegin=0;
LONG ipend=0;
DWORD MaxAddrs[MAX_PATH*200]={0};//最大寻址的地址个数
int naddr=0;
if(TSGetaddr_range(addr_range,ibegin,ipend,MaxAddrs,naddr))
{
if(ibegin>=ipend&&naddr==0)
return bret;
DWORD Pid=0;
//if(my_GetWindowThreadProcessId)
// my_GetWindowThreadProcessId((HWND)hwnd,&Pid);
//else
My_GetWindowThreadProcessId((HWND)hwnd,&Pid);
TSRuntime::EnablePrivilege(L"SeDebugPrivilege",true);
HANDLE hprocess=NULL;
//if(my_OpenProcess)
// hprocess=my_OpenProcess(PROCESS_ALL_ACCESS,false,Pid);
//else
// hprocess=::OpenProcess(PROCESS_ALL_ACCESS,false,Pid);
hprocess=My_OpenProcess(Pid);
if(hprocess==NULL)
{
if(my_ZwOpenProcess)
{
CLIENT_ID Cileid;
Cileid.UniqueProcess=(HANDLE)Pid;
my_ZwOpenProcess(&hprocess,PROCESS_ALL_ACCESS,false,&Cileid);
}
if(hprocess==NULL)
return bret;
}
int retstrlen=0;
DWORD dwRead=0;
int count=0;
if(ibegin>=0&&naddr==0)
{
if(ibegin<0x400000)
ibegin=0x400000;
DWORD nbegin[MAX_PATH*10]={0};
DWORD npend[MAX_PATH*10]={0};
int naddr=0;
GetFindaddr(hprocess,(LPVOID)ibegin,(LPVOID)ipend,nbegin,npend,naddr);
if(naddr==0)
return bret;
if(threadtype)//是否多线程模式
{
DWORD ncpu=GetProcessNumber();//获取CPU个数,决定多线程的个数
HANDLE threadhandle[MAX_PATH]={0};
//双核以下CPU双线程
if(ncpu<=2)
ncpu=2;
else if(ncpu>=8)
ncpu=8;
FindDataInfo info;
info.FindDataType=FINDDATATYPE_FINDINTEX;
info.hprocess=hprocess;
info.int_value_min=int_value_min;
info.int_value_max=int_value_max;
info.FindIntType=type;
info.retstr=retstr;
info.dwncount=naddr;
memcpy(info.dwbegin,nbegin,naddr*sizeof(DWORD));
memcpy(info.dwend,npend,naddr*sizeof(DWORD));
InitializeCriticalSection(&info.m_mutex);
for(int i=0;i<ncpu;i++)
{
threadhandle[i]=(HANDLE)_beginthread(FindDataThread,0,&info);
}
::WaitForMultipleObjects(ncpu,threadhandle,TRUE,INFINITE); //等待所有线程结束后返回
DeleteCriticalSection(&info.m_mutex);
return true;
}
BYTE buffData[4096]={0};
for(int n=0;n<naddr;n++)
{
int size=npend[n]-nbegin[n];
if(size<=4096)
{
::memset(buffData,0,size);
if(ReadProcessMemory(hprocess,LPVOID(nbegin[n]),buffData,size,&dwRead))
{
int i=0;
for(;i<(int)dwRead;i++)
{
if(type==0)//0 : 32位
{
int *value=(int *)&buffData[i];
if(*value>=int_value_min&&*value<=int_value_max)
{
if(count<=20000)
{
wchar_t inx[10]={0};
if(retstrlen==0)
retstrlen=wcslen(retstr);
if(retstrlen==0)
swprintf(inx,L"%X",(ibegin+i));
else
swprintf(inx,L"|%X",(ibegin+i));
wcscat(retstr,inx);
//swprintf(retstr,L"%s|%X",retstr,(ibegin+i));
}
count++;
bret=true;
}
}
else if(type==1) //1 : 16 位
{
short *value=(short *)&buffData[i];
if(*value>=int_value_min&&*value<=int_value_max)
{
if(count<=20000)
{
wchar_t inx[10]={0};
if(retstrlen==0)
retstrlen=wcslen(retstr);
if(retstrlen==0)
swprintf(inx,L"%X",(ibegin+i));
else
swprintf(inx,L"|%X",(ibegin+i));
wcscat(retstr,inx);
//swprintf(retstr,L"%s|%X",retstr,(ibegin+i));
}
count++;
bret=true;
}
}
else if(type==2)//2 : 8位
{
if(buffData[i]>=int_value_min&&buffData[i]<=int_value_max)
{
if(count<=20000)
{
wchar_t inx[10]={0};
if(retstrlen==0)
retstrlen=wcslen(retstr);
if(retstrlen==0)
swprintf(inx,L"%X",(ibegin+i));
else
swprintf(inx,L"|%X",(ibegin+i));
wcscat(retstr,inx);
//swprintf(retstr,L"%s|%X",retstr,(ibegin+i));
}
count++;
bret=true;
}
}
}
}
}
else
{
ibegin=nbegin[n];
int sizen=4096;
while(ibegin<npend[n]&&npend[n]>0)
{
if(ReadProcessMemory(hprocess,LPVOID(ibegin),buffData,sizen,&dwRead))
{
int i=0;
for(;i<(int)dwRead;i++)
{
if(type==0)//0 : 32位
{
int *value=(int *)&buffData[i];
if(*value>=int_value_min&&*value<=int_value_max)
{
if(count<=20000)
{
wchar_t inx[10]={0};
if(retstrlen==0)
retstrlen=wcslen(retstr);
if(retstrlen==0)
swprintf(inx,L"%X",(ibegin+i));
else
swprintf(inx,L"|%X",(ibegin+i));
wcscat(retstr,inx);
//swprintf(retstr,L"%s|%X",retstr,(ibegin+i));
}
count++;
bret=true;
}
}
else if(type==1) //1 : 16 位
{
short *value=(short *)&buffData[i];
if(*value>=int_value_min&&*value<=int_value_max)
{
if(count<=20000)
{
wchar_t inx[10]={0};
if(retstrlen==0)
retstrlen=wcslen(retstr);
if(retstrlen==0)
swprintf(inx,L"%X",(ibegin+i));
else
swprintf(inx,L"|%X",(ibegin+i));
wcscat(retstr,inx);
//swprintf(retstr,L"%s|%X",retstr,(ibegin+i));
}
count++;
bret=true;
}
}
else if(type==2)//2 : 8位
{
if(buffData[i]>=int_value_min&&buffData[i]<=int_value_max)
{
if(count<=20000)
{
wchar_t inx[10]={0};
if(retstrlen==0)
retstrlen=wcslen(retstr);
if(retstrlen==0)
swprintf(inx,L"%X",(ibegin+i));
else
swprintf(inx,L"|%X",(ibegin+i));
wcscat(retstr,inx);
//swprintf(retstr,L"%s|%X",retstr,(ibegin+i));
}
count++;
bret=true;
}
}
}
}
if(npend[n]>=ibegin+4096)
ibegin=ibegin+4096;
else
{
sizen=npend[n]-ibegin;
ibegin=ibegin+4096;
::memset(buffData,0,sizen);
}
}
}
}
//BYTE buffData[4096]={0};
//while(ibegin<ipend&&ibegin>0)
// {
// ::memset(buffData,0,4096);
// if(ReadProcessMemory(hprocess,LPVOID(ibegin),buffData,4096,&dwRead))
// {
// int i=0;
// for(;i<(int)dwRead;i++)
// {
// if(type==0)//0 : 32位
// {
// int *value=(int *)&buffData[i];
// if(*value>=int_value_min&&*value<=int_value_max)
// {
// if(count<=20000)
// {
// if(retstrlen==0)
// retstrlen=wcslen(retstr);
// if(retstrlen==0)
// swprintf(retstr,L"%X",(ibegin+i));
// else
// swprintf(retstr,L"%s|%X",retstr,(ibegin+i));
// }
// count++;
// bret=true;
// }
// }
// else if(type==1) //1 : 16 位
// {
// short *value=(short *)&buffData[i];
// if(*value>=int_value_min&&*value<=int_value_max)
// {
// if(count<=20000)
// {
// if(retstrlen==0)
// retstrlen=wcslen(retstr);
// if(retstrlen==0)
// swprintf(retstr,L"%X",(ibegin+i));
// else
// swprintf(retstr,L"%s|%X",retstr,(ibegin+i));
// }
// count++;
// bret=true;
// }
// }
// else if(type==2)//2 : 8位
// {
// if(buffData[i]>=int_value_min&&buffData[i]<=int_value_max)
// {
// if(count<=20000)
// {
// if(retstrlen==0)
// retstrlen=wcslen(retstr);
// if(retstrlen==0)
// swprintf(retstr,L"%X",(ibegin+i));
// else
// swprintf(retstr,L"%s|%X",retstr,(ibegin+i));
// }
// count++;
// bret=true;
// }
// }
// }
// }
// ibegin=ibegin+4096;
// }
}
else
{
if(type==0)//0 : 32位
{
int value=0;
for(int i=0;i<naddr;i++)
{
if(ReadProcessMemory(hprocess,LPVOID(MaxAddrs[i]),&value,sizeof(int),&dwRead))
{
if(value>=int_value_min&&value<=int_value_max)
{
if(count<=2000)
{
wchar_t inx[10]={0};
if(retstrlen==0)
retstrlen=wcslen(retstr);
if(retstrlen==0)
swprintf(inx,L"%X",MaxAddrs[i]);
else
swprintf(inx,L"|%X",MaxAddrs[i]);
wcscat(retstr,inx);
//swprintf(retstr,L"%s|%X",retstr,MaxAddrs[i]);
}
bret=true;
count++;
}
}
}
}
else if(type==1) //1 : 16 位
{
short value=0;
for(int i=0;i<naddr;i++)
{
if(ReadProcessMemory(hprocess,LPVOID(MaxAddrs[i]),&value,sizeof(short),&dwRead))
{
if(value>=int_value_min&&value<=int_value_max)
{
if(count<=2000)
{
wchar_t inx[10]={0};
if(retstrlen==0)
retstrlen=wcslen(retstr);
if(retstrlen==0)
swprintf(inx,L"%X",MaxAddrs[i]);
else
swprintf(inx,L"|%X",MaxAddrs[i]);
wcscat(retstr,inx);
//swprintf(retstr,L"%s|%X",retstr,MaxAddrs[i]);
}
bret=true;
count++;
}
}
}
}
else if(type==2)//2 : 8位
{
BYTE value=0;
for(int i=0;i<naddr;i++)
{
if(ReadProcessMemory(hprocess,LPVOID(MaxAddrs[i]),&value,sizeof(BYTE),&dwRead))
{
if(value>=int_value_min&&value<=int_value_max)
{
if(count<=2000)
{
wchar_t inx[10]={0};
if(retstrlen==0)
retstrlen=wcslen(retstr);
if(retstrlen==0)
swprintf(inx,L"%X",MaxAddrs[i]);
else
swprintf(inx,L"|%X",MaxAddrs[i]);
wcscat(retstr,inx);
//swprintf(retstr,L"%s|%X",retstr,MaxAddrs[i]);
}
bret=true;
count++;
}
}
}
}
}
}
return bret;
}
bool TSMemoryAPI::TSFindFloat(LONG hwnd,wchar_t * addr_range,wchar_t *retstr,FLOAT float_value_min, FLOAT float_value_max,bool threadtype)
{
// TSRuntime::newstr=NULL;
bool bret=false;
LONG ibegin=0;
LONG ipend=0;
DWORD MaxAddrs[MAX_PATH*200]={0};//最大寻址的地址个数
int naddr=0;
int count=0;
if(TSGetaddr_range(addr_range,ibegin,ipend,MaxAddrs,naddr))
{
if(ibegin>=ipend&&naddr==0)
return bret;
DWORD Pid=0;
//if(my_GetWindowThreadProcessId)
// my_GetWindowThreadProcessId((HWND)hwnd,&Pid);
//else
My_GetWindowThreadProcessId((HWND)hwnd,&Pid);
TSRuntime::EnablePrivilege(L"SeDebugPrivilege",true);
HANDLE hprocess=NULL;
//if(my_OpenProcess)
// hprocess=my_OpenProcess(PROCESS_ALL_ACCESS,false,Pid);
//else
// hprocess=::OpenProcess(PROCESS_ALL_ACCESS,false,Pid);
hprocess=My_OpenProcess(Pid);
if(hprocess==NULL)
{
if(my_ZwOpenProcess)
{
CLIENT_ID Cileid;
Cileid.UniqueProcess=(HANDLE)Pid;
my_ZwOpenProcess(&hprocess,PROCESS_ALL_ACCESS,false,&Cileid);
}
if(hprocess==NULL)
return bret;
}
int retstrlen=0;
DWORD dwRead=0;
if(ibegin>=0&&naddr==0)
{
if(ibegin<0x400000)
ibegin=0x400000;
DWORD nbegin[MAX_PATH*10]={0};
DWORD npend[MAX_PATH*10]={0};
int naddr=0;
GetFindaddr(hprocess,(LPVOID)ibegin,(LPVOID)ipend,nbegin,npend,naddr);
if(naddr==0)
return bret;
if(threadtype)//是否多线程模式
{
memset(TSRuntime::membstr,0,MAX_PATH*200);
DWORD ncpu=GetProcessNumber();//获取CPU个数,决定多线程的个数
HANDLE threadhandle[MAX_PATH]={0};
//双核以下CPU双线程
if(ncpu<=2)
ncpu=2;
else if(ncpu>=8)
ncpu=8;
FindDataInfo info;
info.FindDataType=FINDDATATYPE_FINDFLOATEX;
info.hprocess=hprocess;
info.float_value_min=float_value_min;
info.float_value_max=float_value_max;
info.retstr=retstr;
info.dwncount=naddr;
memcpy(info.dwbegin,nbegin,naddr*sizeof(DWORD));
memcpy(info.dwend,npend,naddr*sizeof(DWORD));
InitializeCriticalSection(&info.m_mutex);
for(int i=0;i<ncpu;i++)
{
threadhandle[i]=(HANDLE)_beginthread(FindDataThread,0,&info);
}
::WaitForMultipleObjects(ncpu,threadhandle,TRUE,INFINITE); //等待所有线程结束后返回
DeleteCriticalSection(&info.m_mutex);
return true;
}
BYTE buffData[4096]={0};
for(int n=0;n<naddr;n++)
{
int size=npend[n]-nbegin[n];
if(size<=4096)
{
::memset(buffData,0,size);
if(ReadProcessMemory(hprocess,LPVOID(nbegin[n]),buffData,size,&dwRead))
{
int i=0;
for(;i<(int)dwRead;i++)
{
float *float_value=(float *)&buffData[i];
if(*float_value>=float_value_min&&*float_value<=float_value_max)
{
if(count<=20000) //记录找到地址的上限为5000,防止溢出
{
wchar_t inx[10]={0};
if(retstrlen==0)
retstrlen=wcslen(retstr);
if(retstrlen==0)
swprintf(inx,L"%X",(ibegin+i));
else
swprintf(inx,L"|%X",(ibegin+i));
wcscat(retstr,inx);
//swprintf(retstr,L"%s|%X",retstr,(ibegin+i));
}
count++;
}
}
}
}
else
{
ibegin=nbegin[n];
int sizen=4096;
while(ibegin<npend[n]&&npend[n]>0)
{
if(ReadProcessMemory(hprocess,LPVOID(ibegin),buffData,sizen,&dwRead))
{
int i=0;
for(;i<(int)dwRead;i++)
{
float *float_value=(float *)&buffData[i];
if(*float_value>=float_value_min&&*float_value<=float_value_max)
{
if(count<=20000) //记录找到地址的上限为5000,防止溢出
{
wchar_t inx[10]={0};
if(retstrlen==0)
retstrlen=wcslen(retstr);
if(retstrlen==0)
swprintf(inx,L"%X",(ibegin+i));
else
swprintf(inx,L"|%X",(ibegin+i));
wcscat(retstr,inx);
//swprintf(retstr,L"%s|%X",retstr,(ibegin+i));
}
count++;
}
}
}
if(npend[n]>=ibegin+4096)
ibegin=ibegin+4096;
else
{
sizen=npend[n]-ibegin;
ibegin=ibegin+4096;
::memset(buffData,0,sizen);
}
}
}
}
//BYTE buffData[4096]={0};
//while(ibegin<ipend&&ibegin>0)
// {
// ::memset(buffData,0,4096);
// if(ReadProcessMemory(hprocess,LPVOID(ibegin),buffData,4096,&dwRead))
// {
// int i=0;
// for(;i<(int)dwRead;i++)
// {
// float *float_value=(float *)&buffData[i];
// if(*float_value>=float_value_min&&*float_value<=float_value_max)
// {
// if(count<=10000)
// {
// if(retstrlen==0)
// retstrlen=wcslen(retstr);
// if(retstrlen==0)
// swprintf(retstr,L"%X",(ibegin+i));
// else
// swprintf(retstr,L"%s|%X",retstr,(ibegin+i));
// }
// count++;
// bret=true;
// }
// }
// }
// ibegin=ibegin+4096;
// }
}
else
{
float buffData=0;
for(int i=0;i<naddr;i++)
{
if(ReadProcessMemory(hprocess,LPVOID(MaxAddrs[i]),&buffData,sizeof(float),&dwRead))
{
if(buffData>=float_value_min&&buffData<=float_value_max)
{
if(count<=10000)
{
wchar_t inx[10]={0};
if(retstrlen==0)
retstrlen=wcslen(retstr);
if(retstrlen==0)
swprintf(inx,L"%X",MaxAddrs[i]);
else
swprintf(inx,L"|%X",MaxAddrs[i]);
wcscat(retstr,inx);
//swprintf(retstr,L"%s|%X",retstr,MaxAddrs[i]);
}
bret=true;
count++;
}
}
}
}
}
//if(bret&&count>1600)
// TSRuntime::newstr=::SysAllocString(retstr);
return bret;
}
bool TSMemoryAPI::TSFindDouble(LONG hwnd,wchar_t * addr_range,wchar_t *retstr,double double_value_min,double double_value_max,bool threadtype)
{
bool bret=false;
LONG ibegin=0;
LONG ipend=0;
DWORD MaxAddrs[MAX_PATH*200]={0};//最大寻址的地址个数
int naddr=0;
if(TSGetaddr_range(addr_range,ibegin,ipend,MaxAddrs,naddr))
{
if(ibegin>=ipend&&naddr==0)
return bret;
DWORD Pid=0;
//if(my_GetWindowThreadProcessId)
// my_GetWindowThreadProcessId((HWND)hwnd,&Pid);
//else
My_GetWindowThreadProcessId((HWND)hwnd,&Pid);
TSRuntime::EnablePrivilege(L"SeDebugPrivilege",true);
HANDLE hprocess=NULL;
//if(my_OpenProcess)
// hprocess=my_OpenProcess(PROCESS_ALL_ACCESS,false,Pid);
//else
// hprocess=::OpenProcess(PROCESS_ALL_ACCESS,false,Pid);
hprocess=My_OpenProcess(Pid);
if(hprocess==NULL)
{
if(my_ZwOpenProcess)
{
CLIENT_ID Cileid;
Cileid.UniqueProcess=(HANDLE)Pid;
my_ZwOpenProcess(&hprocess,PROCESS_ALL_ACCESS,false,&Cileid);
}
if(hprocess==NULL)
return bret;
}
int retstrlen=0;
DWORD dwRead=0;
int count=0;
if(ibegin>=0&&naddr==0)
{
if(ibegin<0x400000)
ibegin=0x400000;
DWORD nbegin[MAX_PATH*10]={0};
DWORD npend[MAX_PATH*10]={0};
int naddr=0;
GetFindaddr(hprocess,(LPVOID)ibegin,(LPVOID)ipend,nbegin,npend,naddr);
if(naddr==0)
return bret;
if(threadtype)//是否多线程模式
{
memset(TSRuntime::membstr,0,MAX_PATH*200);
DWORD ncpu=GetProcessNumber();//获取CPU个数,决定多线程的个数
HANDLE threadhandle[MAX_PATH]={0};
//双核以下CPU双线程
if(ncpu<=2)
ncpu=2;
else if(ncpu>=8)
ncpu=8;
FindDataInfo info;
info.FindDataType=FINDDATATYPE_FINDDOUBLEEX;
info.hprocess=hprocess;
info.double_value_min=double_value_min;
info.double_value_max=double_value_max;
info.retstr=retstr;
info.dwncount=naddr;
memcpy(info.dwbegin,nbegin,naddr*sizeof(DWORD));
memcpy(info.dwend,npend,naddr*sizeof(DWORD));
InitializeCriticalSection(&info.m_mutex);
for(int i=0;i<ncpu;i++)
{
threadhandle[i]=(HANDLE)_beginthread(FindDataThread,0,&info);
}
::WaitForMultipleObjects(ncpu,threadhandle,TRUE,INFINITE); //等待所有线程结束后返回
DeleteCriticalSection(&info.m_mutex);
return true;
}
BYTE buffData[4096]={0};
for(int n=0;n<naddr;n++)
{
int size=npend[n]-nbegin[n];
if(size<=4096)
{
::memset(buffData,0,size);
if(ReadProcessMemory(hprocess,LPVOID(nbegin[n]),buffData,size,&dwRead))
{
int i=0;
for(;i<(int)dwRead;i++)
{
double *double_value=(double *)&buffData[i];
if(*double_value>=double_value_min&&*double_value<=double_value_max)
{
if(count<=20000) //记录找到地址的上限为5000,防止溢出
{
wchar_t inx[10]={0};
if(retstrlen==0)
retstrlen=wcslen(retstr);
if(retstrlen==0)
swprintf(inx,L"%X",(ibegin+i));
else
swprintf(inx,L"|%X",(ibegin+i));
wcscat(retstr,inx);
//swprintf(retstr,L"%s|%X",retstr,(ibegin+i));
}
count++;
}
}
}
}
else
{
ibegin=nbegin[n];
int sizen=4096;
while(ibegin<npend[n]&&npend[n]>0)
{
if(ReadProcessMemory(hprocess,LPVOID(ibegin),buffData,sizen,&dwRead))
{
int i=0;
for(;i<(int)dwRead;i++)
{
double *double_value=(double *)&buffData[i];
if(*double_value>=double_value_min&&*double_value<=double_value_max)
{
if(count<=20000) //记录找到地址的上限为5000,防止溢出
{
wchar_t inx[10]={0};
if(retstrlen==0)
retstrlen=wcslen(retstr);
if(retstrlen==0)
swprintf(inx,L"%X",(ibegin+i));
else
swprintf(inx,L"|%X",(ibegin+i));
wcscat(retstr,inx);
//swprintf(retstr,L"%s|%X",retstr,(ibegin+i));
}
count++;
}
}
}
if(npend[n]>=ibegin+4096)
ibegin=ibegin+4096;
else
{
sizen=npend[n]-ibegin;
ibegin=ibegin+4096;
::memset(buffData,0,sizen);
}
}
}
}
//BYTE buffData[4096]={0};
//while(ibegin<ipend&&ibegin>0)
// {
// ::memset(buffData,0,4096);
// if(ReadProcessMemory(hprocess,LPVOID(ibegin),buffData,4096,&dwRead))
// {
// int i=0;
// for(;i<(int)dwRead;i++)
// {
// double *double_value=(double *)&buffData[i];
// if(*double_value>=double_value_min&&*double_value<=double_value_max)
// {
// if(count<=5000) //记录找到地址的上限为5000,防止溢出
// {
// if(retstrlen==0)
// retstrlen=wcslen(retstr);
// if(retstrlen==0)
// swprintf(retstr,L"%X",(ibegin+i));
// else
// swprintf(retstr,L"%s|%X",retstr,(ibegin+i));
// }
// count++;
// }
// }
// }
// ibegin=ibegin+4096;
// }
}
else
{
double buffData=0;
for(int i=0;i<naddr;i++)
{
if(ReadProcessMemory(hprocess,LPVOID(MaxAddrs[i]),&buffData,sizeof(double),&dwRead))
{
if(buffData>=double_value_min&&buffData<=double_value_max)
{
if(count<=20000) //记录找到地址的上限为5000,防止溢出
{
wchar_t inx[10]={0};
if(retstrlen==0)
retstrlen=wcslen(retstr);
if(retstrlen==0)
swprintf(inx,L"%X",MaxAddrs[i]);
else
swprintf(inx,L"|%X",MaxAddrs[i]);
wcscat(retstr,inx);
//swprintf(retstr,L"%s|%X",retstr,MaxAddrs[i]);
}
count++;
}
}
}
}
}
return bret;
}
bool TSMemoryAPI::TSFindData(LONG hwnd,wchar_t * addr_range,wchar_t *data,wchar_t *retstr,bool threadtype)
{
bool bret=false;
LONG ibegin=0;
LONG ipend=0;
DWORD MaxAddrs[MAX_PATH*200]={0};//最大寻址的地址个数
int naddr=0;
if(wcslen(data)==0||wcslen(addr_range)==0)
return false;
if(TSGetaddr_range(addr_range,ibegin,ipend,MaxAddrs,naddr))
{
if(ibegin>=ipend&&naddr==0)
return bret;
DWORD Pid=0;
//if(my_GetWindowThreadProcessId)
// my_GetWindowThreadProcessId((HWND)hwnd,&Pid);
//else
My_GetWindowThreadProcessId((HWND)hwnd,&Pid);
TSRuntime::EnablePrivilege(L"SeDebugPrivilege",true);
HANDLE hprocess=NULL;
//if(my_OpenProcess)
// hprocess=my_OpenProcess(PROCESS_ALL_ACCESS,false,Pid);
//else
// hprocess=::OpenProcess(PROCESS_ALL_ACCESS,false,Pid);
hprocess=My_OpenProcess(Pid);
if(hprocess==NULL)
{
if(my_ZwOpenProcess)
{
CLIENT_ID Cileid;
Cileid.UniqueProcess=(HANDLE)Pid;
my_ZwOpenProcess(&hprocess,PROCESS_ALL_ACCESS,false,&Cileid);
}
if(hprocess==NULL)
return bret;
}
DWORD dwRead=0;
int nindex=0;
DWORD Finddata[MAX_PATH]={0};
int nconut=0;//返回 data的个数
TSGetDataValue(data,Finddata,nconut);
int retstrlen=0;
int count=0;
if(ibegin>=0&&naddr==0)
{
if(ibegin<0x400000)
ibegin=0x400000;
DWORD nbegin[MAX_PATH*10]={0};
DWORD npend[MAX_PATH*10]={0};
int naddr=0;
GetFindaddr(hprocess,(LPVOID)ibegin,(LPVOID)ipend,nbegin,npend,naddr);
if(naddr==0)
return bret;
if(threadtype)//是否多线程模式
{
DWORD ncpu=GetProcessNumber();//获取CPU个数,决定多线程的个数
HANDLE threadhandle[MAX_PATH]={0};
//双核以下CPU双线程
if(ncpu<=2)
ncpu=2;
else if(ncpu>=8)
ncpu=8;
FindDataInfo info;
info.FindDataType=FINDDATATYPE_FINDDATAEX;
info.hprocess=hprocess;
memcpy(info.Finddata,Finddata,sizeof(DWORD)*nconut);
info.FindIntType=nconut;
info.retstr=retstr;
info.dwncount=naddr;
memcpy(info.dwbegin,nbegin,naddr*sizeof(DWORD));
memcpy(info.dwend,npend,naddr*sizeof(DWORD));
InitializeCriticalSection(&info.m_mutex);
for(int i=0;i<ncpu;i++)
{
threadhandle[i]=(HANDLE)_beginthread(FindDataThread,0,&info);
}
::WaitForMultipleObjects(ncpu,threadhandle,TRUE,INFINITE); //等待所有线程结束后返回
DeleteCriticalSection(&info.m_mutex);
return true;
}
BYTE buffData[4096]={0};
for(int n=0;n<naddr;n++)
{
int size=npend[n]-nbegin[n];
if(size<=4096)
{
::memset(buffData,0,size);
if(ReadProcessMemory(hprocess,LPVOID(nbegin[n]),buffData,size,&dwRead))
{
int i=0;
for(;i<(int)dwRead;i++)
{
if(buffData[i]==Finddata[nindex]||Finddata[nindex]==256)// unknow=256;//标记??模糊查询
{
if(nconut==(nindex+1)) //匹配成功
{
if(count<=20000) //记录找到地址的上限为5000,防止溢出
{
wchar_t inx[10]={0};
if(retstrlen==0)
retstrlen=wcslen(retstr);
if(retstrlen==0)
swprintf(inx,L"%X",(ibegin+i)-nindex);
else
swprintf(inx,L"|%X",(ibegin+i)-nindex);
wcscat(retstr,inx);
//swprintf(retstr,L"%s|%X",retstr,(ibegin+i)-nindex);
}
count++;
nindex=0;
}
nindex++;
}
else
nindex=0;
}
}
}
else
{
ibegin=nbegin[n];
int sizen=4096;
while(ibegin<npend[n]&&npend[n]>0)
{
if(ReadProcessMemory(hprocess,LPVOID(ibegin),buffData,sizen,&dwRead))
{
int i=0;
for(;i<(int)dwRead;i++)
{
if(buffData[i]==Finddata[nindex]||Finddata[nindex]==256)// unknow=256;//标记??模糊查询
{
if(nconut==(nindex+1)) //匹配成功
{
if(count<=20000) //记录找到地址的上限为5000,防止溢出
{
wchar_t inx[10]={0};
if(retstrlen==0)
retstrlen=wcslen(retstr);
if(retstrlen==0)
swprintf(inx,L"%X",(ibegin+i)-nindex);
else
swprintf(inx,L"|%X",(ibegin+i)-nindex);
wcscat(retstr,inx);
//swprintf(retstr,L"%s|%X",retstr,(ibegin+i)-nindex);
}
count++;
nindex=0;
}
nindex++;
}
else
nindex=0;
}
}
if(npend[n]>=ibegin+4096)
ibegin=ibegin+4096;
else
{
sizen=npend[n]-ibegin;
ibegin=ibegin+4096;
::memset(buffData,0,sizen);
}
}
}
}
//byte buffData[4096]={0};
//while(ibegin<ipend&&ibegin>0)
// {
// ::memset(buffData,4096,sizeof(byte)*4096);
// if(ReadProcessMemory(hprocess,LPVOID(ibegin),&buffData,4096,&dwRead))
// {
// for(int i=0;i<dwRead;i++)
// {
// if(buffData[i]==Finddata[nindex]||Finddata[nindex]==256)// unknow=256;//标记??模糊查询
// {
// if(nconut==(nindex+1)) //匹配成功
// {
// if(count<=5000) //记录找到地址的上限为5000,防止溢出
// {
// if(retstrlen==0)
// retstrlen=wcslen(retstr);
// if(retstrlen==0)
// swprintf(retstr,L"%X",(ibegin+i)-nindex);
// else
// swprintf(retstr,L"%s|%X",retstr,(ibegin+i)-nindex);
// }
// count++;
// nindex=0;
// }
// nindex++;
// }
// else
// nindex=0;
//
// }
// }
// ibegin=ibegin+4096;
// }
}
else //地址是地址集合
{
byte buffData[MAX_PATH]={0};
for(int i=0;i<naddr;i++)
{
if(ReadProcessMemory(hprocess,LPVOID(MaxAddrs[i]),&buffData,nconut,&dwRead))
{
for(int i=0;i<nconut;i++)
{
if(buffData[i]==Finddata[nindex]||Finddata[nindex]==256)// unknow=256;//标记??模糊查询
{
if(nconut==(nindex+1)) //匹配成功
{
if(count<=5000) //记录找到地址的上限为5000,防止溢出
{
wchar_t inx[10]={0};
if(retstrlen==0)
retstrlen=wcslen(retstr);
if(retstrlen==0)
swprintf(inx,L"%X",MaxAddrs[i]);
else
swprintf(inx,L"|%X",MaxAddrs[i]);
wcscat(retstr,inx);
// swprintf(retstr,L"%s|%X",retstr,MaxAddrs[i]);
}
count++;
nindex=0;
}
nindex++;
}
else
{
nindex=0;
break;
}
}
}
}
}
}
return bret;
}
bool TSMemoryAPI::TSGetDataValue(wchar_t* strs,DWORD *Data_range,int &nconut)
{
int len=wcslen(strs);
int index=0;
int n=0;
int m=0;
int unknow=0;//标记??模糊查询
wchar_t s[3]={0};
for(int i=0;i<len;i++)
{
if(strs[i]!=' ')
{
s[n]=strs[i];
if(strs[i]=='?')
unknow=256;
if(n==1&&strs[i+1]!=' '&&(i+1)!=len)
{
if(unknow==0)
Data_range[index]=wcstol(s,0,16);
else
{
Data_range[index]=unknow;
unknow=0;
}
memset(s,0,n);
n=0;
m=i;
index++;
continue;
}
n++;
}
else if(n!=0)
{
if(unknow==0)
Data_range[index]=wcstol(s,0,16);
else
{
Data_range[index]=unknow;
unknow=0;
}
memset(s,0,n);
n=0;
m=i;
index++;
}
}
Data_range[index]=wcstol(&strs[m+1],0,16);
nconut=index+1;
return true;
}
bool TSMemoryAPI::TSGetaddr_range(wchar_t* strs,LONG &begin,LONG &end,DWORD *addr_range,int &nconut)
{
bool bret=false;
int len=wcslen(strs);
wchar_t strbegin[16]={0};
wchar_t strend[16]={0};
bool fistrfind=false;
begin=-1;
end=-1;
int index=0;
int n=0;
int m=0;
for(int i=0;i<len;i++,n++)
{
if(strs[i]!='-'&&strs[i]!='|')
strbegin[n]=strs[i];
if(strs[i]=='-')
{
if(i>10)//非法地址
return false;
fistrfind=true;
wcscpy(strend,&strs[i+1]);
break;
}
else if(strs[i]=='|')
{
if(index>=(MAX_PATH*200)-1)
return false;
if(n<=10)//判断是否是非法地址
{
addr_range[index]=wcstol(strbegin,0,16);
index++;
bret=true;
}
memset(strbegin,0,n);
n=-1;
m=i;
}
}
if(fistrfind)
{
begin=wcstol(strbegin,0,16);
end=wcstol(strend,0,16);
bret=true;
}
else
{
addr_range[index]=wcstol(&strs[m+1],0,16); //拷贝最后一个地址
nconut=index+1;
}
return bret;
}
bool TSMemoryAPI::TSValueTypeToData(int type,wchar_t *retstr,double dvalue,float fvalue,int ivalue,wchar_t *svalue,int type1)
{
bool bret=false;
if(type==0)//DoubleToData
{
BYTE bdouble[8]={0};
memcpy(bdouble,&dvalue,8);
for(int i=0;i<8;i++)
{
if(i==0)
{
if(bdouble[i]<0x10)
swprintf(retstr,L"0%x",bdouble[i]);
else
swprintf(retstr,L"%x",bdouble[i]);
}
else
{
if(bdouble[i]<0x10)
swprintf(retstr,L"%s 0%x",retstr,bdouble[i]);
else
swprintf(retstr,L"%s %x",retstr,bdouble[i]);
}
}
}
else if(type==1) //FloatToData
{
BYTE bfolat[4]={0};
memcpy(bfolat,&fvalue,4);
for(int i=0;i<4;i++)
{
if(i==0)
{
if(bfolat[i]<0x10)
swprintf(retstr,L"0%x",bfolat[i]);
else
swprintf(retstr,L"%x",bfolat[i]);
}
else
{
if(bfolat[i]<0x10)
swprintf(retstr,L"%s 0%x",retstr,bfolat[i]);
else
swprintf(retstr,L"%s %x",retstr,bfolat[i]);
}
}
bret=true;
}
else if(type==2)//IntToData
{
//0: 4字节整形数 (一般都选这个)
//1: 2字节整形数
//2: 1字节整形数
int n=0;
BYTE bint[4]={0};
if(type1==0)
{
memcpy(bint,&ivalue,4);
n=4;
}
else if(type1==1)
{
memcpy(bint,&ivalue,2);
n=2;
}
else if(type1==2)
{
memcpy(bint,&ivalue,1);
n=1;
}
if(n==0)
return bret;
for(int i=0;i<n;i++)
{
if(i==0)
{
if(bint[i]<0x10)
swprintf(retstr,L"0%x",bint[i]);
else
swprintf(retstr,L"%x",bint[i]);
}
else
{
if(bint[i]<0x10)
swprintf(retstr,L"%s 0%x",retstr,bint[i]);
else
swprintf(retstr,L"%s %x",retstr,bint[i]);
}
}
bret=true;
}
else if(type==3)//StringToData
{
int len=wcslen(svalue);
USES_CONVERSION;
if(type1==0)//0: 返回Ascii表达的字符串
{
char *bstr=new char[len*2+1];
strcpy(bstr,W2A(svalue));
for(int i=0;i<len;i++)
{
if(i==0)
{
if(bstr[i]<0x10)
swprintf(retstr,L"0%x",bstr[i]);
else
swprintf(retstr,L"%x",bstr[i]);
}
else
{
if(bstr[i]<0x10)
swprintf(retstr,L"%s 0%x",retstr,bstr[i]);
else
swprintf(retstr,L"%s %x",retstr,bstr[i]);
}
}
delete [] bstr;
bret=true;
}
else if(type1==1)//1: 返回Unicode表达的字符串
{
for(int i=0;i<len;i++)
{
if(i==0)
{
if(svalue[i]<0x10)
swprintf(retstr,L"0%x 00",svalue[i]);
else
swprintf(retstr,L"%x 00",svalue[i]);
}
else
{
if(svalue[i]<0x10)
swprintf(retstr,L"%s 0%x 00",retstr,svalue[i]);
else
swprintf(retstr,L"%s %x 00",retstr,svalue[i]);
}
}
bret=true;
}
}
return bret;
}
DWORD TSMemoryAPI::TSGetFindDataAddr(wchar_t* strs, DWORD pid)
{
DWORD readaddr=0;
long longAdd=0;
wchar_t module[MAX_PATH]={0};
int moduleindex=0;//记录模块长度
int nindex=0;//记录指针个数
int noffset=0;//
int index=0;
bool subindex[MAX_PATH]={0};//标记"-"号的位置:true,默认是"+":false
wchar_t offsetaddrstr[MAX_PATH][16]={0};//存储偏移地址
DWORD offsetaddr[MAX_PATH]={0};
for(int i=0;i<MAX_PATH;i++)
{
memset(offsetaddrstr[i],0,16);
}
int len=wcslen(strs);
if(len<1)
{
longAdd=-1;
return longAdd;
}
for(int i=0;i<len;i++)
{
if(strs[i]=='<'||moduleindex>0)
{
if(strs[i]=='>')
{
moduleindex=-1;
}
else if(strs[i+1]!='>')
{
module[moduleindex]=strs[i+1];
moduleindex++;
}
}
if(strs[i]=='>'&&moduleindex==0)
{
longAdd=-1;
return longAdd;
}
if(strs[i]=='[')
nindex++;//记录指针个数
else if(((strs[i]=='+'||index>0)||(strs[i]=='-'||index>0)||moduleindex==0))
{
if(strs[i]=='-')//记录-号的下标
subindex[noffset]=true;
if(strs[i]==']')
{
index=0;
noffset++;
}
else if(strs[i]!=']'&&(strs[i]=='+'||strs[i]=='-'))
{
offsetaddrstr[noffset][index]=strs[i+1];
index++;
i++;
}
else if(strs[i]!=']')
{
offsetaddrstr[noffset][index]=strs[i];
index++;
}
}
else if((noffset==nindex))//记录最后一个偏移地址
{
if(strs[i]=='-')//记录-号的下标
subindex[noffset]=true;
if(strs[i]=='+'||strs[i]=='-')
{
offsetaddrstr[noffset][index]=strs[i+1];
index++;
}
else if(index>0)
{
offsetaddrstr[noffset][index]=strs[i+1];
index++;
}
}
}
DWORD Baseaddr=0;
if(moduleindex==-1)//说明有传入<modulename>
{
HANDLE tlh = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, pid);
MODULEENTRY32 modEntry;
modEntry.dwSize = sizeof(MODULEENTRY32);
Module32First(tlh, &modEntry);
do
{
if(!wcsicmp(module, modEntry.szModule))
{
Baseaddr=(DWORD)modEntry.modBaseAddr;
DWORD handle=modEntry.th32ModuleID;
break;
}
}
while(Module32Next(tlh, &modEntry));
CloseHandle(tlh);
if(Baseaddr==0)
{
longAdd=-1;
return longAdd;
}
}
if(nindex>0) //说明不是一级指针
{
TSRuntime::EnablePrivilege(L"SeDebugPrivilege",true);
HANDLE hprocess=NULL;
//if(my_OpenProcess)
// hprocess=my_OpenProcess(PROCESS_ALL_ACCESS,false,Pid);
//else
// hprocess=::OpenProcess(PROCESS_ALL_ACCESS,false,Pid);
hprocess=My_OpenProcess(pid);
if(hprocess==NULL)
{
if(my_ZwOpenProcess)
{
CLIENT_ID Cileid;
Cileid.UniqueProcess=(HANDLE)pid;
my_ZwOpenProcess(&hprocess,PROCESS_ALL_ACCESS,false,&Cileid);
}
if(hprocess==NULL)
return longAdd;
}
for(int i=0;i<nindex;i++)
{
offsetaddr[i]=wcstol(offsetaddrstr[i],0,16);
if(i==0&&Baseaddr>0)
readaddr=Baseaddr+offsetaddr[i];
else if(i==0)
readaddr=offsetaddr[i];
else if(readaddr!=0)
{
if(subindex[i])
readaddr=longAdd-offsetaddr[i];
else
readaddr=longAdd+offsetaddr[i];
}
longAdd=0;
if(my_ReadProcessMemory)
my_ReadProcessMemory(hprocess,(void*)readaddr,&longAdd,sizeof(longAdd),long(0));
else
::ReadProcessMemory(hprocess,(void*)readaddr,&longAdd,sizeof(longAdd),long(0));
if(longAdd<=0)//说明读取错误地址
{
longAdd=-1;
return longAdd;
}
}
offsetaddr[nindex]=wcstol(offsetaddrstr[nindex],0,16);
if(subindex[nindex])
longAdd=longAdd-offsetaddr[nindex];
else
longAdd=longAdd+offsetaddr[nindex];
CloseHandle(hprocess);
}
else if(moduleindex!=-1)//1367DBC
longAdd=wcstol(strs,0,16);
else if(moduleindex==-1) //<xx.exe>+1367DBC
{
longAdd=wcstol(offsetaddrstr[0],0,16);
longAdd=Baseaddr+longAdd;
}
return longAdd;
}
bool TSMemoryAPI::TSFindString(LONG hwnd,wchar_t * addr_range,wchar_t *retstr,wchar_t*string_value,LONG type,bool threadtype)
{
bool bret=false;
LONG ibegin=0;
LONG ipend=0;
DWORD MaxAddrs[MAX_PATH*200]={0};//最大寻址的地址个数
int naddr=0;
if(TSGetaddr_range(addr_range,ibegin,ipend,MaxAddrs,naddr))
{
if(ibegin>=ipend&&naddr==0)
return bret;
DWORD Pid=0;
//if(my_GetWindowThreadProcessId)
// my_GetWindowThreadProcessId((HWND)hwnd,&Pid);
//else
My_GetWindowThreadProcessId((HWND)hwnd,&Pid);
TSRuntime::EnablePrivilege(L"SeDebugPrivilege",true);
HANDLE hprocess=NULL;
//if(my_OpenProcess)
// hprocess=my_OpenProcess(PROCESS_ALL_ACCESS,false,Pid);
//else
// hprocess=::OpenProcess(PROCESS_ALL_ACCESS,false,Pid);
hprocess=My_OpenProcess(Pid);
if(hprocess==NULL)
{
if(my_ZwOpenProcess)
{
CLIENT_ID Cileid;
Cileid.UniqueProcess=(HANDLE)Pid;
my_ZwOpenProcess(&hprocess,PROCESS_ALL_ACCESS,false,&Cileid);
}
if(hprocess==NULL)
return bret;
}
int retstrlen=0;
DWORD dwRead=0;
int count=0;
int nindex=0;
if(ibegin>=0&&naddr==0)
{
if(ibegin<0x400000)
ibegin=0x400000;
DWORD nbegin[MAX_PATH*10]={0};
DWORD npend[MAX_PATH*10]={0};
int naddr=0;
GetFindaddr(hprocess,(LPVOID)ibegin,(LPVOID)ipend,nbegin,npend,naddr);
if(naddr==0)
return bret;
if(threadtype)//是否多线程模式
{
DWORD ncpu=GetProcessNumber();//获取CPU个数,决定多线程的个数
HANDLE threadhandle[MAX_PATH]={0};
//双核以下CPU双线程
if(ncpu<=2)
ncpu=2;
else if(ncpu>=8)
ncpu=8;
int len=wcslen(string_value);
if(len>=MAX_PATH||len==0)
return bret;
FindDataInfo info;
info.FindDataType=FINDDATATYPE_FINDSTRINGEX;
info.hprocess=hprocess;
wcscpy(info.Findstring,string_value);
info.FindIntType=type; ////0:ASCCII编码查找 1:Unicode编码查找
info.retstr=retstr;
info.dwncount=naddr;
memcpy(info.dwbegin,nbegin,naddr*sizeof(DWORD));
memcpy(info.dwend,npend,naddr*sizeof(DWORD));
InitializeCriticalSection(&info.m_mutex);
for(int i=0;i<ncpu;i++)
{
threadhandle[i]=(HANDLE)_beginthread(FindDataThread,0,&info);
}
::WaitForMultipleObjects(ncpu,threadhandle,TRUE,INFINITE); //等待所有线程结束后返回
DeleteCriticalSection(&info.m_mutex);
return true;
}
//////////////////0:ASCCII编码查找 1:Unicode编码查找//////////////////////////////
if(type == 0)
{
USES_CONVERSION;
int len=wcslen(string_value);
if(len>MAX_PATH||len==0)
return bret;
char chstr[MAX_PATH*2]={0};
strcpy(chstr,W2A(string_value));
len=strlen(chstr);;
BYTE buffData[4096]={0};
for(int n=0;n<naddr;n++)
{
int size=npend[n]-nbegin[n];
if(size<=4096)
{
::memset(buffData,0,size);
if(ReadProcessMemory(hprocess,LPVOID(nbegin[n]),buffData,size,&dwRead))
{
int i=0;
for(;i<(int)dwRead;i++)
{
if(buffData[i]==chstr[nindex])
{
if(len==(nindex+1)) //匹配成功
{
if(count<=20000)
{
wchar_t inx[10]={0};
if(retstrlen==0)
retstrlen=wcslen(retstr);
if(retstrlen==0)
swprintf(inx,L"%X",ibegin+i-nindex);
else
swprintf(inx,L"|%X",ibegin+i-nindex);
wcscat(retstr,inx);
//swprintf(retstr,L"%s|%X",retstr,ibegin+i-nindex);
}
bret=true;
count++;
nindex=0;
}
nindex++;
}
else
nindex=0;
}
}
}
else
{
ibegin=nbegin[n];
int sizen=4096;
while(ibegin<npend[n]&&npend[n]>0)
{
if(ReadProcessMemory(hprocess,LPVOID(ibegin),buffData,sizen,&dwRead))
{
int i=0;
for(;i<(int)dwRead;i++)
{
if(buffData[i]==chstr[nindex])
{
if(len==(nindex+1)) //匹配成功
{
if(count<=20000)
{
wchar_t inx[10]={0};
if(retstrlen==0)
retstrlen=wcslen(retstr);
if(retstrlen==0)
swprintf(inx,L"%X",ibegin+(i-nindex)*2);
else
swprintf(inx,L"|%X",ibegin+(i-nindex)*2);
wcscat(retstr,inx);
//swprintf(retstr,L"%s|%X",retstr,ibegin+i-nindex);
}
bret=true;
count++;
nindex=0;
}
nindex++;
}
else
nindex=0;
}
}
if(npend[n]>=ibegin+4096)
ibegin=ibegin+4096;
else
{
sizen=npend[n]-ibegin;
ibegin=ibegin+4096;
::memset(buffData,0,sizen);
}
}
}
}
//while(ibegin<ipend&&ibegin>0)
// {
// memset(buffData,0,4096);
// if(ReadProcessMemory(hprocess,(PVOID)ibegin,buffData,4096,&dwRead))
// {
// for(int i=0;i<dwRead;i++)
// {
// if(buffData[i]==chstr[nindex])
// {
// if(len==(nindex+1)) //匹配成功
// {
// if(count<=20000)
// {
// if(retstrlen==0)
// retstrlen=wcslen(retstr);
// if(retstrlen==0)
// swprintf(retstr,L"%X",ibegin+i-nindex);
// else
// swprintf(retstr,L"%s|%X",retstr,ibegin+i-nindex);
// }
// bret=true;
// count++;
// nindex=0;
// }
// nindex++;
// }
// else
// nindex=0;
// }
// }
// ibegin=ibegin+4096;
// }
}
else if(type==1)
{
wchar_t buffData[2048]={0};
int len=wcslen(string_value);
if(len>MAX_PATH||len==0)
return bret;
//BYTE buffData[4096]={0};
for(int n=0;n<naddr;n++)
{
int size=npend[n]-nbegin[n];
if(size<=4096)
{
::memset(buffData,0,size);
if(ReadProcessMemory(hprocess,LPVOID(nbegin[n]),buffData,size,&dwRead))
{
int i=0;
for(;i<(int)dwRead;i++)
{
if(buffData[i]==string_value[nindex])
{
if(len==(nindex+1)) //匹配成功
{
if(count<=20000)
{
wchar_t inx[10]={0};
if(retstrlen==0)
retstrlen=wcslen(retstr);
if(retstrlen==0)
swprintf(inx,L"%X",ibegin+(i-nindex)*2);
else
swprintf(inx,L"|%X",ibegin+(i-nindex)*2);
wcscat(retstr,inx);
//swprintf(retstr,L"%s|%X",retstr,ibegin+(i-nindex)*2);
}
bret=true;
count++;
nindex=0;
}
nindex++;
}
else
nindex=0;
}
}
}
else
{
ibegin=nbegin[n];
int sizen=4096;
while(ibegin<npend[n]&&npend[n]>0)
{
if(ReadProcessMemory(hprocess,LPVOID(ibegin),buffData,sizen,&dwRead))
{
int i=0;
for(;i<(int)dwRead;i++)
{
if(buffData[i]==string_value[nindex])
{
if(len==(nindex+1)) //匹配成功
{
if(count<=20000)
{
wchar_t inx[10]={0};
if(retstrlen==0)
retstrlen=wcslen(retstr);
if(retstrlen==0)
swprintf(inx,L"%X",ibegin+(i-nindex)*2);
else
swprintf(inx,L"|%X",ibegin+(i-nindex)*2);
wcscat(retstr,inx);
//swprintf(retstr,L"%s|%X",retstr,ibegin+(i-nindex)*2);
}
bret=true;
count++;
nindex=0;
}
nindex++;
}
else
nindex=0;
}
}
if(npend[n]>=ibegin+4096)
ibegin=ibegin+4096;
else
{
sizen=npend[n]-ibegin;
ibegin=ibegin+4096;
::memset(buffData,0,sizen);
}
}
}
}
//while(ibegin<ipend&&ibegin>0)
// {
// dwRead=0;
// memset(buffData,0,2048*sizeof(wchar_t));
// if(ReadProcessMemory(hprocess,(PVOID)ibegin,buffData,2048*sizeof(wchar_t),&dwRead))
// {
// for(int i=0;i<dwRead;i++)
// {
// if(buffData[i]==string_value[nindex])
// {
// if(len==(nindex+1)) //匹配成功
// {
// if(count<=20000)
// {
// if(retstrlen==0)
// retstrlen=wcslen(retstr);
// if(retstrlen==0)
// swprintf(retstr,L"%X",ibegin+(i-nindex)*2);
// else
// swprintf(retstr,L"%s|%X",retstr,ibegin+(i-nindex)*2);
// }
// bret=true;
// count++;
// nindex=0;
// }
// nindex++;
// }
// else
// nindex=0;
// }
// }
// ibegin=ibegin+2048*sizeof(wchar_t);
// //ibegin=ibegin+4096-findLength;
// }
}
}
else //重复查找
{
//////////////////0:ASCCII编码查找 1:Unicode编码查找//////////////////////////////
if(type==0)//0 : ASCCII
{
char buffData[MAX_PATH*2]={0};
USES_CONVERSION;
int len=wcslen(string_value);
if(len>MAX_PATH)
return bret;
char value[MAX_PATH*2]={0};
strcpy(value,W2A(string_value));
len=strlen(value);
for(int i=0;i<naddr;i++)
{
if(ReadProcessMemory(hprocess,LPVOID(MaxAddrs[i]),&buffData,len,&dwRead))
{
if(::memcmp(buffData,value,len)==0)
{
if(count<=20000)
{
wchar_t inx[10]={0};
if(retstrlen==0)
retstrlen=wcslen(retstr);
if(retstrlen==0)
swprintf(inx,L"%X",MaxAddrs[i]);
else
swprintf(inx,L"|%X",MaxAddrs[i]);
wcscat(retstr,inx);
//swprintf(retstr,L"%s|%X",retstr,MaxAddrs[i]);
}
bret=true;
count++;
}
}
}
}
else if(type==1) //1 :Unicode
{
wchar_t buffData[MAX_PATH]={0};
int len=wcslen(string_value);
for(int i=0;i<naddr;i++)
{
if(ReadProcessMemory(hprocess,LPVOID(MaxAddrs[i]),&buffData,len,&dwRead))
{
if(::memcmp(buffData,string_value,len)==0)
{
if(count<=20000)
{
wchar_t inx[10]={0};
if(retstrlen==0)
retstrlen=wcslen(retstr);
if(retstrlen==0)
swprintf(inx,L"%X",MaxAddrs[i]);
else
swprintf(inx,L"|%X",MaxAddrs[i]);
wcscat(retstr,inx);
//swprintf(retstr,L"%s|%X",retstr,MaxAddrs[i]);
}
bret=true;
count++;
}
}
}
}
}
}
return bret;
}
bool TSMemoryAPI::TSReadData(LONG hwnd,wchar_t*addr,wchar_t *retstr,LONG len)
{
bool bret=false;
if(len<0||len>MAX_PATH)
return bret;
DWORD pid=0;
//if(my_GetWindowThreadProcessId)
// my_GetWindowThreadProcessId((HWND)hwnd,&Pid);
//else
My_GetWindowThreadProcessId((HWND)hwnd,&pid);
DWORD findaddr=TSGetFindDataAddr(addr,pid);
if(findaddr==-1)
return bret;
TSRuntime::EnablePrivilege(L"SeDebugPrivilege",true);
HANDLE hprocess=NULL;
//if(my_OpenProcess)
// hprocess=my_OpenProcess(PROCESS_ALL_ACCESS,false,Pid);
//else
// hprocess=::OpenProcess(PROCESS_ALL_ACCESS,false,Pid);
hprocess=My_OpenProcess(pid);
if(hprocess==NULL)
{
if(my_ZwOpenProcess)
{
CLIENT_ID Cileid;
Cileid.UniqueProcess=(HANDLE)pid;
my_ZwOpenProcess(&hprocess,PROCESS_ALL_ACCESS,false,&Cileid);
}
if(hprocess==NULL)
return bret;
}
BYTE finddata[MAX_PATH]={0};
DWORD dwread=0;
if(my_ReadProcessMemory)
my_ReadProcessMemory(hprocess, (LPCVOID)findaddr,finddata,len,&dwread);
else
::ReadProcessMemory(hprocess, (LPCVOID)findaddr,finddata,len,&dwread);
if(dwread>0)
{
for(int i=0;i<len;i++)
{
if(i==0)
{
if(finddata[i]<0x10)
{
if(finddata[i]>=0)
swprintf(retstr,L"%s 0%X",retstr,finddata[i]);
else
{
LONG val=finddata[i]-0xffffff00;
swprintf(retstr,L"%s %X",retstr,val);
}
}
else
swprintf(retstr,L"%X",finddata[i]);
bret=true;
}
else
{
if(finddata[i]<0x10)
{
if(finddata[i]>=0)
swprintf(retstr,L"%s 0%X",retstr,finddata[i]);
else
{
LONG val=finddata[i]-0xffffff00;
swprintf(retstr,L"%s %X",retstr,val);
}
}
else
swprintf(retstr,L"%s %X",retstr,finddata[i]);
bret=true;
}
}
}
CloseHandle(hprocess);
return bret;
}
bool TSMemoryAPI::TSReadDouble(LONG hwnd,wchar_t*addr,double &dvalue,float &fvalue,int type)
{
bool bret=false;
DWORD pid=0;
//if(my_GetWindowThreadProcessId)
// my_GetWindowThreadProcessId((HWND)hwnd,&Pid);
//else
My_GetWindowThreadProcessId((HWND)hwnd,&pid);
DWORD findaddr=TSGetFindDataAddr(addr,pid);
if(findaddr==-1)
return bret;
TSRuntime::EnablePrivilege(L"SeDebugPrivilege",true);
HANDLE hprocess=NULL;
//if(my_OpenProcess)
// hprocess=my_OpenProcess(PROCESS_ALL_ACCESS,false,Pid);
//else
// hprocess=::OpenProcess(PROCESS_ALL_ACCESS,false,Pid);
hprocess=My_OpenProcess(pid);
if(hprocess==NULL)
{
if(my_ZwOpenProcess)
{
CLIENT_ID Cileid;
Cileid.UniqueProcess=(HANDLE)pid;
my_ZwOpenProcess(&hprocess,PROCESS_ALL_ACCESS,false,&Cileid);
}
if(hprocess==NULL)
return bret;
}
DWORD dwread=0;
if(type==0)//type0:DOUBLE,1:FLOAT
{
double readdouble=0;
if(my_ReadProcessMemory)
my_ReadProcessMemory(hprocess, (LPCVOID)findaddr,&readdouble,sizeof(double),&dwread);
else
::ReadProcessMemory(hprocess, (LPCVOID)findaddr,&readdouble,sizeof(double),&dwread);
dvalue=readdouble;
}
else if(type==1)
{
float readfloat=0;
if(my_ReadProcessMemory)
my_ReadProcessMemory(hprocess, (LPCVOID)findaddr,&readfloat,sizeof(float),&dwread);
else
::ReadProcessMemory(hprocess, (LPCVOID)findaddr,&readfloat,sizeof(float),&dwread);
fvalue=readfloat;
}
CloseHandle(hprocess);
if(dwread!=0)
bret=true;
return bret;
}
bool TSMemoryAPI::TSReadInt(LONG hwnd,wchar_t*addr,int &ivalue,short &svalue,BYTE &bvalue,int type)
{
bool bret=false;
DWORD pid=0;
//if(my_GetWindowThreadProcessId)
// my_GetWindowThreadProcessId((HWND)hwnd,&Pid);
//else
My_GetWindowThreadProcessId((HWND)hwnd,&pid);
DWORD findaddr=TSGetFindDataAddr(addr,pid);
if(findaddr==-1)
return bret;
TSRuntime::EnablePrivilege(L"SeDebugPrivilege",true);
HANDLE hprocess=NULL;
//if(my_OpenProcess)
// hprocess=my_OpenProcess(PROCESS_ALL_ACCESS,false,Pid);
//else
// hprocess=::OpenProcess(PROCESS_ALL_ACCESS,false,Pid);
hprocess=My_OpenProcess(pid);
if(hprocess==NULL)
{
if(my_ZwOpenProcess)
{
CLIENT_ID Cileid;
Cileid.UniqueProcess=(HANDLE)pid;
my_ZwOpenProcess(&hprocess,PROCESS_ALL_ACCESS,false,&Cileid);
}
if(hprocess==NULL)
return bret;
}
DWORD dwread=0;
//0 : 32位
//1 : 16 位
//2 : 8位
if(type==0)
{
int value=0;
if(my_ReadProcessMemory)
my_ReadProcessMemory(hprocess, (LPCVOID)findaddr,&value,sizeof(int),&dwread);
else
::ReadProcessMemory(hprocess, (LPCVOID)findaddr,&value,sizeof(int),&dwread);
ivalue=value;
}
else if(type==1)
{
short value=0;
if(my_ReadProcessMemory)
my_ReadProcessMemory(hprocess, (LPCVOID)findaddr,&value,sizeof(short),&dwread);
else
::ReadProcessMemory(hprocess, (LPCVOID)findaddr,&value,sizeof(short),&dwread);
svalue=value;
}
else if(type==2)
{
BYTE value=0;
if(my_ReadProcessMemory)
my_ReadProcessMemory(hprocess, (LPCVOID)findaddr,&value,sizeof(BYTE),&dwread);
else
::ReadProcessMemory(hprocess, (LPCVOID)findaddr,&value,sizeof(BYTE),&dwread);
bvalue=value;
}
CloseHandle(hprocess);
if(dwread!=0)
bret=true;
return bret;
}
bool TSMemoryAPI::TSReadString(LONG hwnd,wchar_t*addr,wchar_t *retstr,LONG len,int type)
{
bool bret=false;
if(len>MAX_PATH)
return bret;
DWORD pid=0;
//if(my_GetWindowThreadProcessId)
// my_GetWindowThreadProcessId((HWND)hwnd,&Pid);
//else
My_GetWindowThreadProcessId((HWND)hwnd,&pid);
DWORD findaddr=TSGetFindDataAddr(addr,pid);
if(findaddr==-1)
return bret;
TSRuntime::EnablePrivilege(L"SeDebugPrivilege",true);
HANDLE hprocess=NULL;
//if(my_OpenProcess)
// hprocess=my_OpenProcess(PROCESS_ALL_ACCESS,false,Pid);
//else
// hprocess=::OpenProcess(PROCESS_ALL_ACCESS,false,Pid);
hprocess=My_OpenProcess(pid);
if(hprocess==NULL)
{
if(my_ZwOpenProcess)
{
CLIENT_ID Cileid;
Cileid.UniqueProcess=(HANDLE)pid;
my_ZwOpenProcess(&hprocess,PROCESS_ALL_ACCESS,false,&Cileid);
}
if(hprocess==NULL)
return bret;
}
DWORD dwread=0;
////0 : GBK字符串
////1 :Unicode字符串
if(type==0)
{
char strvalue[MAX_PATH]={0};
if(my_ReadProcessMemory)
my_ReadProcessMemory(hprocess, (LPCVOID)findaddr,strvalue,len,&dwread);
else
::ReadProcessMemory(hprocess, (LPCVOID)findaddr,strvalue,len,&dwread);
USES_CONVERSION;
wcscpy(retstr,A2W(strvalue));
}
else if(type==1)
{
wchar_t wstrvlue[MAX_PATH]={0};
if(my_ReadProcessMemory)
my_ReadProcessMemory(hprocess, (LPCVOID)findaddr,wstrvlue,len*sizeof(wchar_t),&dwread);
else
::ReadProcessMemory(hprocess, (LPCVOID)findaddr,wstrvlue,len*sizeof(wchar_t),&dwread);
wcscpy(retstr,wstrvlue);
}
CloseHandle(hprocess);
if(dwread!=0)
bret=true;
return bret;
}
bool TSMemoryAPI::TSTerminateProcess(LONG pid)
{
bool bret=false;
TSRuntime::EnablePrivilege(L"SeDebugPrivilege",true);
HANDLE hprocess=NULL;
//if(my_OpenProcess)
// hprocess=my_OpenProcess(PROCESS_ALL_ACCESS,false,Pid);
//else
// hprocess=::OpenProcess(PROCESS_ALL_ACCESS,false,Pid);
hprocess=My_OpenProcess(pid);
if(hprocess==NULL)
{
if(my_ZwOpenProcess)
{
CLIENT_ID Cileid;
Cileid.UniqueProcess=(HANDLE)pid;
my_ZwOpenProcess(&hprocess,PROCESS_ALL_ACCESS,false,&Cileid);
}
if(hprocess==NULL)
return bret;
}
if(my_TerminateProcess)
bret=my_TerminateProcess(hprocess,0);
else
bret=::TerminateProcess(hprocess,0);
CloseHandle(hprocess);
return bret;
}
bool TSMemoryAPI::TSVirtualAllocEx(LONG hwnd,LONG &addr,LONG size,LONG type)
{
bool bret=false;
DWORD pid=0;
//if(my_GetWindowThreadProcessId)
// my_GetWindowThreadProcessId((HWND)hwnd,&Pid);
//else
My_GetWindowThreadProcessId((HWND)hwnd,&pid);
TSRuntime::EnablePrivilege(L"SeDebugPrivilege",true);
HANDLE hprocess=NULL;
//if(my_OpenProcess)
// hprocess=my_OpenProcess(PROCESS_ALL_ACCESS,false,Pid);
//else
// hprocess=::OpenProcess(PROCESS_ALL_ACCESS,false,Pid);
hprocess=My_OpenProcess(pid);
if(hprocess==NULL)
{
if(my_ZwOpenProcess)
{
CLIENT_ID Cileid;
Cileid.UniqueProcess=(HANDLE)pid;
my_ZwOpenProcess(&hprocess,PROCESS_ALL_ACCESS,false,&Cileid);
}
if(hprocess==NULL)
return bret;
}
DWORD dwtype=0;
if(type==0)//可读可写可执行
{
dwtype=PAGE_EXECUTE_READWRITE;
}
else//1 : 可读可执行,不可写
{
dwtype=PAGE_EXECUTE_READ;
}
LPVOID retaddr=NULL;
if(dwtype!=0)
retaddr=::VirtualAllocEx(hprocess,(void*)addr,size,MEM_COMMIT,dwtype);
CloseHandle(hprocess);
addr=(DWORD)retaddr;
return bret;
}
bool TSMemoryAPI::TSVirtualFreeEx(LONG hwnd,LONG addr)
{
bool bret=false;
DWORD pid=0;
//if(my_GetWindowThreadProcessId)
// my_GetWindowThreadProcessId((HWND)hwnd,&Pid);
//else
My_GetWindowThreadProcessId((HWND)hwnd,&pid);
TSRuntime::EnablePrivilege(L"SeDebugPrivilege",true);
HANDLE hprocess=NULL;
//if(my_OpenProcess)
// hprocess=my_OpenProcess(PROCESS_ALL_ACCESS,false,Pid);
//else
// hprocess=::OpenProcess(PROCESS_ALL_ACCESS,false,Pid);
hprocess=My_OpenProcess(pid);
if(hprocess==NULL)
{
if(my_ZwOpenProcess)
{
CLIENT_ID Cileid;
Cileid.UniqueProcess=(HANDLE)pid;
my_ZwOpenProcess(&hprocess,PROCESS_ALL_ACCESS,false,&Cileid);
}
if(hprocess==NULL)
return bret;
}
bret=::VirtualFreeEx(hprocess,(void*)addr,0,MEM_RELEASE);
CloseHandle(hprocess);
return bret;
}
bool TSMemoryAPI::TSWriteData(LONG hwnd,wchar_t * addr,wchar_t *data)
{
bool bret=false;
DWORD pid=0;
//if(my_GetWindowThreadProcessId)
// my_GetWindowThreadProcessId((HWND)hwnd,&Pid);
//else
My_GetWindowThreadProcessId((HWND)hwnd,&pid);
DWORD findaddr=TSGetFindDataAddr(addr,pid);
if(findaddr==-1)
return bret;
TSRuntime::EnablePrivilege(L"SeDebugPrivilege",true);
HANDLE hprocess=NULL;
//if(my_OpenProcess)
// hprocess=my_OpenProcess(PROCESS_ALL_ACCESS,false,Pid);
//else
// hprocess=::OpenProcess(PROCESS_ALL_ACCESS,false,Pid);
hprocess=My_OpenProcess(pid);
if(hprocess==NULL)
{
if(my_ZwOpenProcess)
{
CLIENT_ID Cileid;
Cileid.UniqueProcess=(HANDLE)pid;
my_ZwOpenProcess(&hprocess,PROCESS_ALL_ACCESS,false,&Cileid);
}
if(hprocess==NULL)
return bret;
}
DWORD dwwrite=0;
DWORD Finddata[MAX_PATH]={0};
int nconut=0;//返回 data的个数
TSGetDataValue(data,Finddata,nconut);
if(nconut<=0)
return bret;
BYTE strvalue[MAX_PATH*10]={0};
for(int i=0;i<nconut;i++)
{
strvalue[i]=Finddata[i];
}
DWORD dwback;
if(my_VirtualProtectEx)
my_VirtualProtectEx(hprocess,(void*)findaddr, nconut, PAGE_EXECUTE_READWRITE, &dwback);
else
::VirtualProtectEx(hprocess,(void*)findaddr, nconut, PAGE_EXECUTE_READWRITE, &dwback);
if(my_WriteProcessMemory)
bret=my_WriteProcessMemory(hprocess, (void*)findaddr,strvalue,nconut,&dwwrite);
else
bret=::WriteProcessMemory(hprocess, (void*)findaddr,strvalue,nconut,&dwwrite);
if(my_VirtualProtectEx)
bret=my_VirtualProtectEx(hprocess,(void*)findaddr, nconut, dwback, &dwback);
else
bret=::VirtualProtectEx(hprocess,(void*)findaddr, nconut, dwback, &dwback);
CloseHandle(hprocess);
return bret;
}
bool TSMemoryAPI::TSWriteDouble(LONG hwnd,wchar_t *addr,DOUBLE dvalue,FLOAT fvlaue)
{
bool bret=false;
DWORD pid=0;
//if(my_GetWindowThreadProcessId)
// my_GetWindowThreadProcessId((HWND)hwnd,&Pid);
//else
My_GetWindowThreadProcessId((HWND)hwnd,&pid);
DWORD findaddr=TSGetFindDataAddr(addr,pid);
if(findaddr==-1)
return bret;
TSRuntime::EnablePrivilege(L"SeDebugPrivilege",true);
HANDLE hprocess=NULL;
//if(my_OpenProcess)
// hprocess=my_OpenProcess(PROCESS_ALL_ACCESS,false,Pid);
//else
// hprocess=::OpenProcess(PROCESS_ALL_ACCESS,false,Pid);
hprocess=My_OpenProcess(pid);
if(hprocess==NULL)
{
if(my_ZwOpenProcess)
{
CLIENT_ID Cileid;
Cileid.UniqueProcess=(HANDLE)pid;
my_ZwOpenProcess(&hprocess,PROCESS_ALL_ACCESS,false,&Cileid);
}
if(hprocess==NULL)
return bret;
}
DWORD dwback;
if(my_VirtualProtectEx)
my_VirtualProtectEx(hprocess,(void*)findaddr, sizeof(DOUBLE), PAGE_EXECUTE_READWRITE, &dwback);
else
::VirtualProtectEx(hprocess,(void*)findaddr, sizeof(DOUBLE), PAGE_EXECUTE_READWRITE, &dwback);
DWORD dwwrite=0;
if(dvalue!=0)
{
if(my_WriteProcessMemory)
bret=my_WriteProcessMemory(hprocess, (void*)findaddr,&dvalue,sizeof(DOUBLE),&dwwrite);
else
bret=::WriteProcessMemory(hprocess, (void*)findaddr,&dvalue,sizeof(DOUBLE),&dwwrite);
}
else if(fvlaue!=0)
{
if(my_WriteProcessMemory)
bret=my_WriteProcessMemory(hprocess, (void*)findaddr,&fvlaue,sizeof(FLOAT),&dwwrite);
else
bret=::WriteProcessMemory(hprocess, (void*)findaddr,&fvlaue,sizeof(FLOAT),&dwwrite);
}
if(my_VirtualProtectEx)
bret=my_VirtualProtectEx(hprocess,(void*)findaddr,sizeof(DOUBLE), dwback, &dwback);
else
bret=::VirtualProtectEx(hprocess,(void*)findaddr, sizeof(DOUBLE), dwback, &dwback);
CloseHandle(hprocess);
return bret;
}
bool TSMemoryAPI::TSWriteInt(LONG hwnd,wchar_t *addr,int ivalue,short svalue,BYTE bvalue)
{
bool bret=false;
DWORD pid=0;
//if(my_GetWindowThreadProcessId)
// my_GetWindowThreadProcessId((HWND)hwnd,&Pid);
//else
My_GetWindowThreadProcessId((HWND)hwnd,&pid);
DWORD findaddr=TSGetFindDataAddr(addr,pid);
if(findaddr==-1)
return bret;
TSRuntime::EnablePrivilege(L"SeDebugPrivilege",true);
HANDLE hprocess=NULL;
//if(my_OpenProcess)
// hprocess=my_OpenProcess(PROCESS_ALL_ACCESS,false,Pid);
//else
// hprocess=::OpenProcess(PROCESS_ALL_ACCESS,false,Pid);
hprocess=My_OpenProcess(pid);
if(hprocess==NULL)
{
if(my_ZwOpenProcess)
{
CLIENT_ID Cileid;
Cileid.UniqueProcess=(HANDLE)pid;
my_ZwOpenProcess(&hprocess,PROCESS_ALL_ACCESS,false,&Cileid);
}
if(hprocess==NULL)
return bret;
}
DWORD dwwrite=0;
DWORD dwback;
if(my_VirtualProtectEx)
my_VirtualProtectEx(hprocess,(void*)findaddr, sizeof(int), PAGE_EXECUTE_READWRITE, &dwback);
else
::VirtualProtectEx(hprocess,(void*)findaddr, sizeof(int), PAGE_EXECUTE_READWRITE, &dwback);
if(ivalue!=0)
{
if(my_WriteProcessMemory)
bret=my_WriteProcessMemory(hprocess, (void*)findaddr,&ivalue,sizeof(int),&dwwrite);
else
bret=::WriteProcessMemory(hprocess, (void*)findaddr,&ivalue,sizeof(int),&dwwrite);
}
else if(svalue!=0)
{
if(my_WriteProcessMemory)
bret=my_WriteProcessMemory(hprocess, (void*)findaddr,&svalue,sizeof(short),&dwwrite);
else
bret=::WriteProcessMemory(hprocess, (void*)findaddr,&svalue,sizeof(short),&dwwrite);
}
else if(bvalue!=0)
{
if(my_WriteProcessMemory)
bret=my_WriteProcessMemory(hprocess, (void*)findaddr,&bvalue,sizeof(BYTE),&dwwrite);
else
bret=::WriteProcessMemory(hprocess, (void*)findaddr,&bvalue,sizeof(BYTE),&dwwrite);
}
if(my_VirtualProtectEx)
bret= my_VirtualProtectEx(hprocess,(void*)findaddr, sizeof(int), dwback, &dwback);
else
bret=::VirtualProtectEx(hprocess,(void*)findaddr, sizeof(int), dwback, &dwback);
CloseHandle(hprocess);
return bret;
}
bool TSMemoryAPI::TSWriteString(LONG hwnd,wchar_t*addr,wchar_t* strvalue,LONG type)
{
bool bret=false;
int len=wcslen(strvalue);
if(len==0||len>MAX_PATH)
return bret;
DWORD pid=0;
//if(my_GetWindowThreadProcessId)
// my_GetWindowThreadProcessId((HWND)hwnd,&Pid);
//else
My_GetWindowThreadProcessId((HWND)hwnd,&pid);
DWORD findaddr=TSGetFindDataAddr(addr,pid);
if(findaddr==-1)
return bret;
TSRuntime::EnablePrivilege(L"SeDebugPrivilege",true);
HANDLE hprocess=NULL;
//if(my_OpenProcess)
// hprocess=my_OpenProcess(PROCESS_ALL_ACCESS,false,Pid);
//else
// hprocess=::OpenProcess(PROCESS_ALL_ACCESS,false,Pid);
hprocess=My_OpenProcess(pid);
if(hprocess==NULL)
{
if(my_ZwOpenProcess)
{
CLIENT_ID Cileid;
Cileid.UniqueProcess=(HANDLE)pid;
my_ZwOpenProcess(&hprocess,PROCESS_ALL_ACCESS,false,&Cileid);
}
if(hprocess==NULL)
return bret;
}
DWORD dwwrite=0;
DWORD dwback;
if(my_VirtualProtectEx)
my_VirtualProtectEx(hprocess,(void*)findaddr, len, PAGE_EXECUTE_READWRITE, &dwback);
else
::VirtualProtectEx(hprocess,(void*)findaddr, len, PAGE_EXECUTE_READWRITE, &dwback);
if(type==0)//Ascii字符串
{
USES_CONVERSION;
char strchar[MAX_PATH*2]={0};
strcpy(strchar,W2A(strvalue));
int len=strlen(strchar);
if(my_ReadProcessMemory)
my_WriteProcessMemory(hprocess, (void*)findaddr,strchar,len,&dwwrite);
else
::WriteProcessMemory(hprocess, (void*)findaddr,strchar,len,&dwwrite);
}
else if(type==1)
{
if(my_ReadProcessMemory)
bret= my_WriteProcessMemory(hprocess, (void*)findaddr,strvalue,len,&dwwrite);
else
bret= ::WriteProcessMemory(hprocess, (void*)findaddr,strvalue,len,&dwwrite);
}
if(my_VirtualProtectEx)
bret=my_VirtualProtectEx(hprocess,(void*)findaddr, len, dwback, &dwback);
else
bret= ::VirtualProtectEx(hprocess,(void*)findaddr, len, dwback, &dwback);
CloseHandle(hprocess);
return bret;
}
bool TSMemoryAPI::GetFindaddr(HANDLE hprocess,PVOID lpbegin,PVOID lpend,DWORD *ibegin,DWORD *ipend,int &ncount)
{
bool bret=false;
int index=0;
SYSTEM_INFO si_info;
MEMORY_BASIC_INFORMATION mbi;
DWORD rett;
GetSystemInfo(&si_info);
DWORD len = sizeof(MEMORY_BASIC_INFORMATION);
PVOID addr = si_info.lpMinimumApplicationAddress;
bool bfind=false;
do
{
rett =VirtualQueryEx(hprocess,addr,&mbi,len);
if(mbi.Type==MEM_IMAGE||mbi.Type==MEM_PRIVATE) //找到了块
{
//MessageBox(0,L"找到了块",0,0);
if(lpbegin==0)
lpbegin=LPVOID(mbi.AllocationBase);
else if(bfind==false)
lpbegin=addr;
if(lpend==0)
{
lpend=si_info.lpMaximumApplicationAddress;
}
ibegin[index]=int(lpbegin);
ipend[index]=int(lpend);
bfind=true;
//break;
}
else
{
if(ibegin!=0&&bfind==true)
{
ipend[index]=(DWORD)mbi.BaseAddress + mbi.RegionSize;
bfind=false;
index++;
bret=true;
}
}
addr= ((PBYTE)mbi.BaseAddress + mbi.RegionSize);
}while(rett==len);
ncount=index;
for(int i=0;i<index;i++)
{
if(((DWORD)ipend[i]-(DWORD)ibegin[i])>0xF00000)
{
DWORD end=ipend[i];
ipend[i]=ibegin[i]+0xF00000;
DWORD iend=ipend[i];
while((end-(DWORD)iend)>0xF00000)
{
ibegin[ncount]=iend;
ipend[ncount]=ibegin[ncount]+0xF00000;
ncount++;
iend=iend+0xF00000;
}
ibegin[ncount]=iend;
ipend[ncount]=end;
ncount++;
}
}
return bret;
}
bool TSMemoryAPI::TSGetCmdLine(LONG hwnd,wchar_t *retstr)
{
bool bret=false;
DWORD dwPID=0;
//if(my_GetWindowThreadProcessId)
// my_GetWindowThreadProcessId((HWND)hwnd,&Pid);
//else
My_GetWindowThreadProcessId((HWND)hwnd,&dwPID);
TSRuntime::EnablePrivilege(L"SeDebugPrivilege",true);
HANDLE hprocess=NULL;
//if(my_OpenProcess)
// hprocess=my_OpenProcess(PROCESS_ALL_ACCESS,false,Pid);
//else
// hprocess=::OpenProcess(PROCESS_ALL_ACCESS,false,Pid);
hprocess=My_OpenProcess(dwPID);
if(hprocess==NULL)
{
if(my_ZwOpenProcess)
{
CLIENT_ID Cileid;
Cileid.UniqueProcess=(HANDLE)dwPID;
my_ZwOpenProcess(&hprocess,PROCESS_ALL_ACCESS,false,&Cileid);
}
if(hprocess==NULL)
return bret;
}
NtQueryInformationProcess = (PROCNTQSIP)GetProcAddress(GetModuleHandle(L"ntdll"),"NtQueryInformationProcess");
PROCESS_BASIC_INFORMATION pbis;
PEB pebs;
PROCESS_PARAMETERS ppms;
TCHAR *text = 0;
NtQueryInformationProcess(hprocess, 0, &pbis, sizeof(PROCESS_BASIC_INFORMATION),0);
ReadProcessMemory(hprocess, pbis.PebBaseAddress, &pebs, sizeof(PEB), 0);
ReadProcessMemory(hprocess, pebs.ProcessParameters, &ppms, sizeof(PROCESS_PARAMETERS), 0);
text = (TCHAR *)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, ppms.CommandLine.MaximumLength);
ReadProcessMemory(hprocess, ppms.CommandLine.Buffer, text, ppms.CommandLine.Length, 0);
if(text)
{
wcscpy(retstr,text);
bret=true;
}
::HeapFree(GetProcessHeap(),HEAP_NO_SERIALIZE,text);
return bret;
}
bool TSMemoryAPI::TSAsmAdd(wchar_t*asm_ins)
{
bool bret=false;
char asmcode[MAX_PATH]={0};
USES_CONVERSION;
strcpy(asmcode,W2A(asm_ins));
char erro[MAX_PATH]={0};
int len=-1;
char *charcall=strstr(::CharLowerA(asmcode),"call");
if(charcall!=NULL)//判断是否是Call指令,记住Call地址
{
if(strlen(Asmcalladdr)==0)
strcpy(Asmcalladdr,charcall);
return true;
}
else
len= tsasm.Assemble(asmcode,NULL,&am,0,0,erro); //将汇编指令转为机器码
if(len<0)
return bret;
else
bret=true;
for(int i=0;i<len;i++)
{
char asmcodes[10]={0};
if(am.code[i]>=0x10)
sprintf(asmcodes,"%X",am.code[i]);
else
sprintf(asmcodes,"0%X",am.code[i]);
if(am.code[i]!=0)
asmcodearry=asmcodearry+asmcodes;//这里做拼接
else
{
int serlen=asmcodearry.length();
serlen=serlen+1;
asmcodearry.resize(serlen);
}
}
//int charlen=strlen(asmcode);
//int serlen=asmcodearry.length();
//if(charlen<len)
// asmcodearry.resize(serlen+(len-charlen));
return bret;
}
DWORD TSMemoryAPI::GetCallstartData(DWORD Allocaddr,DWORD * startaddr,char *code)//获取CALL地址前的汇编指令
{
CMgAsmBase::t_asmmodel tam;
char erro[MAX_PATH]={0};
char asmcode[MAX_PATH]={0};
Allocaddr=Allocaddr+0x1000;
if(code==NULL)
sprintf(asmcode,"push %x",Allocaddr);
else
sprintf(asmcode,"%s",code);
LONG l=tsasm.Assemble(asmcode,Allocaddr,&tam,0,0,erro); //将汇编指令转为机器码
for(int i=0;i<l;i++)
{
startaddr[i]=tam.code[i];
}
return l;
}
bool TSMemoryAPI::TSAsmCall(LONG hwnd,LONG mode)
{
bool bret=false;
int len=asmcodearry.length();
if(strlen(Asmcalladdr)<=0)
return bret;
DWORD dwPID=0;
DWORD treadid=0;
//if(my_GetWindowThreadProcessId)
// my_GetWindowThreadProcessId((HWND)hwnd,&Pid);
//else
My_GetWindowThreadProcessId((HWND)hwnd,&dwPID);
TSRuntime::EnablePrivilege(L"SeDebugPrivilege",true);
HANDLE hprocess=NULL;
if(mode==1) //1 : 对hwnd指定的进程内执行,注入模式为创建远程线程
{
//if(my_OpenProcess)
// hprocess=my_OpenProcess(PROCESS_ALL_ACCESS,false,Pid);
//else
// hprocess=::OpenProcess(PROCESS_ALL_ACCESS,false,Pid);
hprocess=My_OpenProcess(dwPID);
if(hprocess==NULL)
{
if(my_ZwOpenProcess)
{
CLIENT_ID Cileid;
Cileid.UniqueProcess=(HANDLE)dwPID;
my_ZwOpenProcess(&hprocess,PROCESS_ALL_ACCESS,false,&Cileid);
}
if(hprocess==NULL)
return bret;
}
}
else if(mode==0) //0 : 在本进程中进行执行,这时hwnd无效
{
hprocess=::GetCurrentProcess();
treadid=GetCurrentThreadId();
}
else
{
return bret;
}
if(allocatememory)
{
::VirtualFreeEx(hprocess,allocatememory,0,MEM_RELEASE);
allocatememory=NULL;
}
allocatememory=::VirtualAllocEx(hprocess,NULL,0x2000,MEM_COMMIT|MEM_RESERVE,PAGE_EXECUTE_READWRITE);
if(allocatememory)
{
char retstring[MAX_PATH*10]={0};
int retstrlen=0;
if(len!=0)
{
//asmcodearry="9C60"+asmcodearry;//pushfd,pushad;保持堆栈平衡
len=asmcodearry.length();
for(int i=0;i<len;i++)
{
int stringlen=0;
{
stringlen=strlen(&asmcodearry.c_str()[i]);
if(stringlen>0)
{
LONG val=::strtol(&asmcodearry.c_str()[i],0,16);
if(val>=0x10)
{
if(val<=0xff)
{
if(retstrlen==0)
retstrlen=strlen(retstring);
if(retstrlen==0)
sprintf(retstring,"%s",&asmcodearry.c_str()[i]);
else
sprintf(retstring,"%s %s",retstring,&asmcodearry.c_str()[i]);
}
else
{
int len=strlen(&asmcodearry.c_str()[i]);
char str[16]={0};
strcpy(str,&asmcodearry.c_str()[i]);
for(int n=0;n<len;n=n+2)
{
char nstr[2]={0};
strncpy(nstr,&str[n],2);
int strn=strtol(nstr,0,16);
if(n+2!=len||n+2<len)
{
if(retstrlen==0)
retstrlen=strlen(retstring);
if(retstrlen==0)
{
if(strn>=0x10)
sprintf(retstring,"%X",strn);
else
sprintf(retstring,"0%X",strn);
}
else
{
if(strn>=0x10)
sprintf(retstring,"%s %X",retstring,strn);
else
sprintf(retstring,"%s 0%X",retstring,strn);
}
}
else
{
if(len%2==0)
{
if(strn>=0x10)
sprintf(retstring,"%s %X",retstring,strn);
else
sprintf(retstring,"%s 0%X",retstring,strn);
}
else
{
if(strn>=0x10)
sprintf(retstring,"%s %X",retstring,strn);
else
sprintf(retstring,"%s 0%X",retstring,strn);
}
}
}
}
}
else
sprintf(retstring,"%s 0%s",retstring,&asmcodearry.c_str()[i]);
i=i+stringlen-1;
}
else
sprintf(retstring,"%s 00",retstring);
}
}
}
DWORD datas[MAX_PATH*10]={0};
int count=0;
int lenth=0;
if(strlen(retstring)>0)
{
DWORD data[10]={0};
int len=GetCallstartData((DWORD)allocatememory,data);
for (int i=0;i<len;i++)
{
datas[i] = data[i];
}
memset(data,0,len);
int l=len;
lenth=lenth+len;
len=GetCallstartData((DWORD)allocatememory+l,data,"push dword ptr fs:[0]");
for (int i=0;i<len;i++)
{
datas[lenth+i] = data[i];
}
memset(data,0,len);
l=len;
lenth=lenth+len;
len=GetCallstartData((DWORD)allocatememory+l,data,"mov dword ptr fs:[0],esp");
for (int i=0;i<len;i++)
{
datas[lenth+i] = data[i];
}
lenth=lenth+len;
USES_CONVERSION;
wchar_t wretsting[MAX_PATH*10]={0};
wcscpy(wretsting,A2W(retstring));
TSGetDataValue(wretsting,&datas[lenth],count);
}
BYTE helpByte[MAX_PATH*10] = {0};
for (int i=0;i<count+lenth;i++)
{
helpByte[i] = datas[i];
}
char erro[MAX_PATH]={0};
int calllen= tsasm.Assemble(Asmcalladdr,((DWORD)allocatememory+count+lenth),&am,0,0,erro); //将汇编指令转为机器码
if(calllen>0)
{
memcpy(&helpByte[count+lenth],am.code,calllen);
calllen=calllen+count+lenth;
if(count!=0)
{
BYTE CallendData[]={0x8b,0x1c,0x24,0x64,0x89,0x1d,0x0,0x0,0x0,0x0,0x81,0xc4,0x08,0x0,0x0,0x0,0xc2,0x04,0x0};
//CallendData存储的机器码对应汇编指令
//mov ebx,dword ptr ss:[esp]
//mov dword ptr fs:[0],ebx
//add esp,0x8
//retn 0x4;
memcpy(&helpByte[calllen],CallendData,sizeof(CallendData));
calllen=calllen+sizeof(CallendData)+1;
}
if(my_WriteProcessMemory)
bret=my_WriteProcessMemory(hprocess, (void*)allocatememory,(void*)helpByte,calllen,0);
else
bret=::WriteProcessMemory(hprocess, (void*)allocatememory,(void*)helpByte,calllen,0);
HANDLE hthread=NULL;
////判断是否DX绑定窗口
//char pszMapName[MAX_PATH]={0};
//DWORD Pid=0;
//My_GetWindowThreadProcessId((HWND)hwnd,&Pid);
//sprintf( pszMapName,"%s%d",TS_MAPVIEW_NAME,Pid);
//HANDLE hFileMap = OpenFileMappingA(FILE_MAP_ALL_ACCESS, FALSE, pszMapName);
//////如果hFileMap句柄不为空说明DLL绑定注入
//if(hFileMap!=NULL) //说明已经DX绑定
// hthread=(HANDLE)::SendMessage((HWND)hwnd,TS_ASMCALL,(WPARAM)allocatememory,0);
//else
hthread=::CreateRemoteThread(hprocess,NULL,0,(LPTHREAD_START_ROUTINE)(allocatememory),0,0,&treadid);
//CloseHandle(hFileMap);
if(hthread!=NULL)
bret=true;
DWORD ExitCode=0;
//Sleep(50);//等待50毫秒,等待线程执行完毕
::GetExitCodeThread(hthread,&ExitCode);
if(ExitCode!=STILL_ACTIVE)//判断线程是否退出
if(allocatememory)
{
::VirtualFreeEx(hprocess,allocatememory,0,MEM_RELEASE);
allocatememory=NULL;
}
}
}
asmcodearry.clear();
memset(Asmcalladdr,0,MAX_PATH);
return bret;
}
bool TSMemoryAPI::TSAsmClear()
{
asmcodearry.clear();
memset(Asmcalladdr,0,MAX_PATH);
return true;
}
bool TSMemoryAPI::TSAsmCode(LONG base_addr,wchar_t *retstr)
{
bool bret=false;
int len=asmcodearry.length();
char retstring[MAX_PATH*10]={0};
int retstrlen=0;
for(int i=0;i<len;i++)
{
int stringlen=0;
{
stringlen=strlen(&asmcodearry.c_str()[i]);
if(stringlen>0)
{
LONG val=::strtol(&asmcodearry.c_str()[i],0,16);
if(val>=0x10)
{
if(val<=0xff)
{
if(retstrlen==0)
retstrlen=strlen(retstring);
if(retstrlen==0)
sprintf(retstring,"%s",&asmcodearry.c_str()[i]);
else
sprintf(retstring,"%s %s",retstring,&asmcodearry.c_str()[i]);
}
else
{
int len=strlen(&asmcodearry.c_str()[i]);
char str[MAX_PATH]={0};
strcpy(str,&asmcodearry.c_str()[i]);
for(int n=0;n<len;n=n+2)
{
char nstr[2]={0};
strncpy(nstr,&str[n],2);
int strn=strtol(nstr,0,16);
if(n+2!=len||n+2<len)
{
if(retstrlen==0)
retstrlen=strlen(retstring);
if(retstrlen==0)
{
if(strn>=0x10)
sprintf(retstring,"%X",strn);
else
sprintf(retstring,"0%X",strn);
}
else
{
if(strn>=0x10)
sprintf(retstring,"%s %X",retstring,strn);
else
sprintf(retstring,"%s 0%X",retstring,strn);
}
}
else
{
if(len%2==0)
{
if(strn>=0x10)
sprintf(retstring,"%s %X",retstring,strn);
else
sprintf(retstring,"%s 0%X",retstring,strn);
}
else
{
if(strn>=0x10)
sprintf(retstring,"%s %X",retstring,strn);
else
sprintf(retstring,"%s 0%X",retstring,strn);
}
}
}
}
}
else
sprintf(retstring,"%s 0%s",retstring,&asmcodearry.c_str()[i]);
i=i+stringlen-1;
}
else
sprintf(retstring,"%s 00",retstring);
}
bret=true;
}
if(strlen(Asmcalladdr)!=0)
{
char erro[MAX_PATH]={0};
int calllen=tsasm.Assemble(Asmcalladdr,base_addr,&am,0,0,erro); //将汇编指令转为机器码
for(int i=0;i<calllen;i++)
{
if(strlen(retstring)==0)
{
if(am.code[i]>=0)
if(am.code[i]>=0x10)
sprintf(retstring,"%X",am.code[i]);
else
sprintf(retstring,"%s 0%X",retstring,am.code[i]);
else
{
LONG val=am.code[i]-0xffffff00;
if(val>=0x10)
sprintf(retstring,"%s %X",retstring,val);
else
sprintf(retstring,"%s 0%X",retstring,val);
}
}
else
{
if(am.code[i]>=0)
if(am.code[i]>=0x10)
sprintf(retstring,"%s %X",retstring,am.code[i]);
else
sprintf(retstring,"%s 0%X",retstring,am.code[i]);
else
{
LONG val=am.code[i]-0xffffff00;
if(val>=0x10)
sprintf(retstring,"%s %X",retstring,val);
else
sprintf(retstring,"%s 0%X",retstring,val);
}
};
bret=true;
}
}
USES_CONVERSION;
wcscpy(retstr,A2W(retstring));
return bret;
}
bool TSMemoryAPI::TSAssemble(wchar_t * asm_code,LONG base_addr,LONG is_upper,wchar_t *retstr)
{
bool bret=false;
if(wcslen(asm_code)<=0)
return bret;
CMgDisasmBase::t_disasm da;
tsdsm.m_nIDEAL=0; tsdsm.m_nLowercase=is_upper; tsdsm.m_nPutDefSeg=0;
DWORD datas[MAX_PATH*10]={0};
int count=0;
TSGetDataValue(asm_code,datas,count);
if(count<=0)
return bret;
BYTE helpByte[MAX_PATH*10] = {0};
for (int i=0;i<count;i++)
{
helpByte[i] = datas[i];
}
ulong l=tsdsm.Disasm((char*)helpByte,count,0,&da,DISASM_CODE);
USES_CONVERSION;
wcscpy(retstr,A2W(da.result));
return bret;
}
bool TSMemoryAPI::TSFreeProcessMemory(LONG hwnd)
{
DWORD nPid=0;
My_GetWindowThreadProcessId((HWND)hwnd,&nPid);
TSRuntime::EnablePrivilege(L"SeDebugPrivilege",true);
HANDLE hprocess=NULL;
hprocess=My_OpenProcess(nPid);
SetProcessWorkingSetSize(hprocess,-1,-1);
//内存整理
EmptyWorkingSet(hprocess);
CloseHandle(hprocess);
return true;
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/yenmuse/TSPlug.git
git@gitee.com:yenmuse/TSPlug.git
yenmuse
TSPlug
TSPlug
master

搜索帮助