Skip to content

Commit 5131d38

Browse files
committed
Test01-AB1.1
1 parent 2dcc02b commit 5131d38

8 files changed

Lines changed: 474 additions & 79 deletions

File tree

control

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: com.vanson.modifier
22
Name: VansonModifier
3-
Version: 3.1.2
3+
Version: 3.1.2.1
44
Architecture: iphoneos-arm
55
Description: Vanson U Know?
66
Maintainer: Vanson

include/VMMemoryEngine.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,16 @@ typedef enum : NSUInteger {
150150
isNextSearch:(BOOL)isNext
151151
completion:(void (^)(NSUInteger count, NSString *msg))comp;
152152

153+
// Multi-type: in one logical search, it goes through several types
154+
// (the first scan adds the results of each type to one set).
155+
// The results are mixed - each stores its own type; next/filter is checked per-item.
156+
- (void)scanMemoryWithMode:(VMSearchMode)mode
157+
valStr:(NSString *)valStr
158+
dataTypes:(NSArray<NSNumber *> *)types
159+
fuzzyType:(VMFuzzyType)fuzzyType
160+
isNextSearch:(BOOL)isNext
161+
completion:(void (^)(NSUInteger count, NSString *msg))comp;
162+
153163
- (void)scanMemoryWithMode:(VMSearchMode)mode
154164
valStr:(NSString *)valStr
155165
coreDataType:(uint8_t)coreType

src/memory/VMMemoryEngine.mm

Lines changed: 77 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -641,16 +641,89 @@ - (void)scanMemoryWithMode:(VMSearchMode)mode
641641
fuzzyType:(VMFuzzyType)fuzzyType
642642
isNextSearch:(BOOL)isNext
643643
completion:(void (^)(NSUInteger count, NSString *msg))comp {
644-
645-
VMCore::DataType coreType = convertToCoreDataType(type);
644+
646645
[self scanMemoryWithMode:mode
647646
valStr:valStr
648-
coreDataType:(uint8_t)coreType
647+
dataTypes:@[ @(type) ]
649648
fuzzyType:fuzzyType
650649
isNextSearch:isNext
651650
completion:comp];
652651
}
653652

653+
- (void)scanMemoryWithMode:(VMSearchMode)mode
654+
valStr:(NSString *)valStr
655+
dataTypes:(NSArray<NSNumber *> *)types
656+
fuzzyType:(VMFuzzyType)fuzzyType
657+
isNextSearch:(BOOL)isNext
658+
completion:(void (^)(NSUInteger count, NSString *msg))comp {
659+
660+
if (self.targetTask == MACH_PORT_NULL) {
661+
if (comp)
662+
comp(0, TR(@"Msg_Target_Not_Found"));
663+
return;
664+
}
665+
if (types.count == 0) {
666+
if (comp)
667+
comp(0, TR(@"Msg_Search_No_Res"));
668+
return;
669+
}
670+
671+
VMDataType primary = (VMDataType)[types.firstObject unsignedIntegerValue];
672+
self.currentDataType = primary;
673+
674+
// Snapshot of the list of types in C++ for a background thread
675+
std::vector<VMCore::DataType> coreTypes;
676+
coreTypes.reserve(types.count);
677+
for (NSNumber *t in types) {
678+
coreTypes.push_back(convertToCoreDataType((VMDataType)[t unsignedIntegerValue]));
679+
}
680+
681+
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
682+
std::string cValStr = [valStr UTF8String] ?: "";
683+
int cMode = (int)mode;
684+
685+
if (isNext) {
686+
int finalMode;
687+
if (mode == VMSearchModeExact) {
688+
finalMode = 100;
689+
} else if (mode == VMSearchModeBetween) {
690+
finalMode = 101;
691+
} else if (mode == VMSearchModeFuzzy) {
692+
finalMode = (int)fuzzyType;
693+
} else {
694+
finalMode = cMode;
695+
}
696+
// Core re-checks each result by its own stored type - representative type isn't critical
697+
_core->nextScan({}, coreTypes.front(), cValStr, finalMode);
698+
} else {
699+
_core->clearBaselineSnapshot();
700+
701+
// First scan: iterate each type, appending results into one set
702+
bool first = true;
703+
for (VMCore::DataType ct : coreTypes) {
704+
_core->scan(ct, cValStr, cMode, self.searchRangeStart,
705+
self.searchRangeEnd, /*append=*/!first);
706+
first = false;
707+
}
708+
709+
if (mode == VMSearchModeFuzzy && _core->getResultCount() > 0) {
710+
_core->saveBaselineSnapshot();
711+
}
712+
}
713+
714+
self.resultCount = _core->getResultCount();
715+
self.resultFilePath = self.resultCount > 0 ? [self getPathA] : nil;
716+
717+
dispatch_async(dispatch_get_main_queue(), ^{
718+
if (comp) {
719+
NSString *msg = self.resultCount > 0 ? TR(@"Msg_Search_Success")
720+
: TR(@"Msg_Search_No_Res");
721+
comp(self.resultCount, msg);
722+
}
723+
});
724+
});
725+
}
726+
654727
- (void)scanMemoryWithMode:(VMSearchMode)mode
655728
valStr:(NSString *)valStr
656729
coreDataType:(uint8_t)coreType
@@ -822,7 +895,7 @@ - (VMScanResultItem *)getResultItemAtIndex:(NSUInteger)index
822895
item.address = cppItem.address;
823896

824897
VMDataType actualType = (VMDataType)cppItem.type;
825-
if (actualType >= VMDataTypeInt8 && actualType <= VMDataTypeDouble) {
898+
if (actualType >= VMDataTypeInt8 && actualType <= VMDataTypeString) {
826899
item.type = actualType;
827900
} else {
828901
item.type = type;

src/memory/core/MemoryCore.cpp

Lines changed: 44 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -494,12 +494,14 @@ void MemoryCore::parseRangeString(const std::string &rangeStr, DataType type,
494494
std::vector<ScanResult> MemoryCore::scan(DataType type,
495495
const std::string &valueStr,
496496
int searchMode, uint64_t start,
497-
uint64_t end) {
498-
_resultCount = 0;
497+
uint64_t end, bool append) {
498+
if (!append)
499+
_resultCount = 0;
499500
std::vector<ScanResult> emptyRes;
500501
if (_task == MACH_PORT_NULL || _storagePath.empty())
501502
return emptyRes;
502-
FILE *outFile = fopen(_storagePath.c_str(), "wb");
503+
// append=true: add the following type of results to the same file (multi-type)
504+
FILE *outFile = fopen(_storagePath.c_str(), append ? "ab" : "wb");
503505
if (!outFile)
504506
return emptyRes;
505507

@@ -976,54 +978,46 @@ MemoryCore::nextScan(const std::vector<ScanResult> &ignored, DataType type,
976978
}
977979
}
978980

979-
union {
980-
int8_t i8;
981-
int16_t i16;
982-
int32_t i32;
983-
int64_t i64;
984-
float f;
985-
double d;
986-
} target;
987-
memset(&target, 0, sizeof(target));
988-
989-
parseValue(valueStr, type, &target);
990-
991-
// Parse range for between mode (101)
992-
union {
993-
int8_t i8; int16_t i16; int32_t i32; int64_t i64;
994-
float f; double d;
995-
} rangeMin, rangeMax;
996-
memset(&rangeMin, 0, sizeof(rangeMin));
997-
memset(&rangeMax, 0, sizeof(rangeMax));
981+
// Multi-type: we parse the target for all widths at once, so that each result is
982+
// checked against ITS stored type (raw.type), and not against requestedType.
983+
int64_t targetIntRaw = 0;
984+
double targetDoubleRaw = 0;
985+
parseValue(valueStr, DataType::Int64, &targetIntRaw);
986+
parseValue(valueStr, DataType::Double, &targetDoubleRaw);
987+
988+
// Parse range for between mode (101) - separate integer and real numbers
989+
int64_t rangeMinIntRaw = 0, rangeMaxIntRaw = 0;
990+
double rangeMinDoubleRaw = 0, rangeMaxDoubleRaw = 0;
998991
if (searchMode == 101) {
999-
parseRangeString(valueStr, type, &rangeMin, &rangeMax);
992+
parseRangeString(valueStr, DataType::Int64, &rangeMinIntRaw, &rangeMaxIntRaw);
993+
parseRangeString(valueStr, DataType::Double, &rangeMinDoubleRaw, &rangeMaxDoubleRaw);
1000994
}
1001-
995+
1002996
bool isStringType = (type == DataType::String);
1003997
std::string targetString = valueStr;
1004998
size_t targetStringLen = targetString.length();
1005999

10061000
std::atomic<size_t> newCount(0);
10071001
mach_port_t task = _task;
1008-
1009-
float targetFloat = target.f;
1010-
double targetDouble = target.d;
1011-
1012-
int8_t targetI8 = target.i8;
1013-
int16_t targetI16 = target.i16;
1014-
int32_t targetI32 = target.i32;
1015-
int64_t targetI64 = target.i64;
1002+
1003+
float targetFloat = (float)targetDoubleRaw;
1004+
double targetDouble = targetDoubleRaw;
1005+
1006+
int8_t targetI8 = (int8_t)targetIntRaw;
1007+
int16_t targetI16 = (int16_t)targetIntRaw;
1008+
int32_t targetI32 = (int32_t)targetIntRaw;
1009+
int64_t targetI64 = targetIntRaw;
10161010
double floatTolerance = _floatTolerance;
1017-
1011+
10181012
std::vector<DiffRegion> diffRegionsCopy = diffRegions;
10191013
bool useIncremental = useIncrementalOptimization;
1020-
1014+
10211015
// Range variables for between mode (101)
1022-
float rangeMinFloat = rangeMin.f, rangeMaxFloat = rangeMax.f;
1023-
double rangeMinDouble = rangeMin.d, rangeMaxDouble = rangeMax.d;
1024-
int64_t rangeMinI64 = rangeMin.i64, rangeMaxI64 = rangeMax.i64;
1025-
1026-
DataType requestedType = type;
1016+
float rangeMinFloat = (float)rangeMinDoubleRaw, rangeMaxFloat = (float)rangeMaxDoubleRaw;
1017+
double rangeMinDouble = rangeMinDoubleRaw, rangeMaxDouble = rangeMaxDoubleRaw;
1018+
int64_t rangeMinI64 = rangeMinIntRaw, rangeMaxI64 = rangeMaxIntRaw;
1019+
1020+
(void)isStringType; // stringiness is determined by per-item by raw.type
10271021

10281022
const size_t chunkSizeInResults = 500000;
10291023
size_t processed = 0;
@@ -1081,8 +1075,8 @@ MemoryCore::nextScan(const std::vector<ScanResult> &ignored, DataType type,
10811075
}
10821076

10831077
uint8_t buf[8];
1084-
1085-
if (isStringType) {
1078+
1079+
if ((DataType)raw.type == DataType::String) {
10861080
mach_vm_size_t rSz = 64;
10871081
if (mach_vm_read_overwrite(task, raw.address, 64,
10881082
(mach_vm_address_t)stringBuffer,
@@ -1133,13 +1127,8 @@ MemoryCore::nextScan(const std::vector<ScanResult> &ignored, DataType type,
11331127
}
11341128
}
11351129

1136-
DataType storedType = (DataType)raw.type;
1137-
DataType actualType = storedType;
1130+
DataType actualType = (DataType)raw.type;
11381131
size_t actualSize = getSizeForType(actualType);
1139-
1140-
if (storedType != requestedType) {
1141-
continue;
1142-
}
11431132

11441133
bool readSuccess = false;
11451134
if (cachedPage != (uint64_t)-1) {
@@ -1463,9 +1452,7 @@ MemoryCore::scanNearby(const std::vector<ScanResult> &baseResults,
14631452
FILE *fOut = fopen(_swapPath.c_str(), "wb");
14641453
if (fOut) {
14651454
for (const auto &res : results) {
1466-
RawResult raw;
1467-
raw.address = res.address;
1468-
raw.value = res.value.u64;
1455+
RawResult raw = makeRawResult(res.address, res.value.u64, res.type);
14691456
fwrite(&raw, sizeof(RawResult), 1, fOut);
14701457
}
14711458
fclose(fOut);
@@ -1840,7 +1827,7 @@ size_t MemoryCore::filterResults(FilterMode mode, DataType type,
18401827
}
18411828
RawResult item;
18421829
size_t newCount = 0;
1843-
size_t dataSize = getSizeForType(type);
1830+
(void)type; // the filter checks each result by its type (item.type)
18441831

18451832
uint64_t cachedPage = (uint64_t)-1;
18461833
uint8_t pageBuffer[4096];
@@ -1849,7 +1836,10 @@ size_t MemoryCore::filterResults(FilterMode mode, DataType type,
18491836
uint8_t buf[8];
18501837
memset(buf, 0, 8);
18511838

1852-
uint64_t pageAddr = item.address & ~0xFFF;
1839+
DataType itemType = (DataType)item.type;
1840+
size_t dataSize = getSizeForType(itemType);
1841+
1842+
uint64_t pageAddr = item.address & ~0xFFF;
18531843
if (pageAddr != cachedPage) {
18541844
cachedPage = pageAddr;
18551845
mach_vm_size_t readSz = 4096;
@@ -1881,9 +1871,9 @@ size_t MemoryCore::filterResults(FilterMode mode, DataType type,
18811871

18821872
if (readSuccess) {
18831873
double currentVal = 0;
1884-
if (type == DataType::Float)
1874+
if (itemType == DataType::Float)
18851875
currentVal = *(float *)buf;
1886-
else if (type == DataType::Double)
1876+
else if (itemType == DataType::Double)
18871877
currentVal = *(double *)buf;
18881878
else if (dataSize == 1)
18891879
currentVal = *(int8_t *)buf;

src/memory/core/MemoryCore.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class MemoryCore {
8282

8383
std::vector<ScanResult> scan(DataType type, const std::string &valueStr,
8484
int searchMode, uint64_t start = 0,
85-
uint64_t end = 0);
85+
uint64_t end = 0, bool append = false);
8686

8787
std::vector<ScanResult>
8888
nextScan(const std::vector<ScanResult> &previousResults, DataType type,

0 commit comments

Comments
 (0)