This function can be called from vmx-root mode Do NOT directly call this function as the virtual addresses should be valid on the target process memory layout instead call : SearchAddressWrapper the address between StartAddress and EndAddress should be contiguous
682{
683 UINT32 CountOfOccurance = 0;
685 UINT32 IndexToArrayOfResults = 0;
686 UINT32 LengthOfEachChunk = 0;
687 PVOID TempSourceAddress = 0;
688 PVOID SourceAddress = 0;
692
693
694
695
697 {
698 LengthOfEachChunk = 1;
699 }
701 {
702 LengthOfEachChunk = 4;
703 }
705 {
706 LengthOfEachChunk = 8;
707 }
708 else
709 {
710
711
712
714 }
715
716
717
718
721 {
722
723
724
725
726
727
728
729
730 if (IsDebuggeePaused)
731 {
732
733
734
736 }
737 else
738 {
740 {
742 }
743 }
744
745
746
747
748
750
751 for (
size_t BaseIterator = (
size_t)StartAddress; BaseIterator < ((
UINT64)EndAddress); BaseIterator += LengthOfEachChunk)
752 {
753
754
755
756
757
758
759
760
761
762 if (IsDebuggeePaused)
763 {
765 }
766 else
767 {
768 RtlCopyMemory(&Cmp64, (PVOID)BaseIterator, LengthOfEachChunk);
769 }
770
771
772
773
774 TempValue = *(
UINT64 *)SourceAddress;
775
776
777
778
779 if (Cmp64 == TempValue)
780 {
781
782
783
785
786
787
788
789
790 for (
size_t i = LengthOfEachChunk; i < SearchMemRequest->
CountOf64Chunks; i++)
791 {
792
793
794
796
797
798
799
800
801
802 if (IsDebuggeePaused)
803 {
805 }
806 else
807 {
808 RtlCopyMemory(&Cmp64, (PVOID)(BaseIterator + (LengthOfEachChunk * i)), LengthOfEachChunk);
809 }
810
811
812
813
814
815 if (IsDebuggeePaused)
816 {
818 }
819 else
820 {
821 TempValue = *(
UINT64 *)TempSourceAddress;
822 }
823
824 if (!(Cmp64 == TempValue))
825 {
826
827
828
830
831
832
833
834 break;
835 }
836 }
837
838
839
840
841 if (StillMatch)
842 {
843
844
845
846
847 CountOfOccurance++;
848
849 if (IsDebuggeePaused)
850 {
852 {
853
854
855
857 }
858 else
859 {
860
861
862
863 Log(
"%llx\n", BaseIterator);
864 }
865 }
866 else
867 {
869 {
870
871
872
874 }
875 else
876 {
877
878
879
880 AddressToSaveResults[IndexToArrayOfResults] = BaseIterator;
881 }
882 }
883
884
885
886
888 {
889 IndexToArrayOfResults++;
890 }
891 else
892 {
893
894
895
896 *CountOfMatchedCases = CountOfOccurance;
898 }
899 }
900 }
901 else
902 {
903
904
905
906 continue;
907 }
908 }
909
910
911
912
913
915 {
917 }
918 }
920 {
921
922
923
924
925 LogError(
"Err, searching physical memory is not allowed without virtual address");
926
928 }
929 else
930 {
931
932
933
935 }
936
937
938
939
940 *CountOfMatchedCases = CountOfOccurance;
942}
#define Log(format,...)
Log without any prefix.
Definition HyperDbgHyperLogIntrinsics.h:129
#define LogError(format,...)
Log in the case of error.
Definition HyperDbgHyperLogIntrinsics.h:113
CR3_TYPE LayoutGetCurrentProcessCr3()
Get cr3 of the target running process.
Definition Layout.c:55
_Use_decl_annotations_ BOOLEAN MemoryMapperReadMemorySafe(UINT64 VaAddressToRead, PVOID BufferToSaveMemory, SIZE_T SizeToRead)
Read memory safely by mapping the buffer (It's a wrapper)
Definition MemoryMapper.c:1101
@ SEARCH_QWORD
Definition RequestStructures.h:518
@ SEARCH_BYTE
Definition RequestStructures.h:516
@ SEARCH_DWORD
Definition RequestStructures.h:517
@ SEARCH_PHYSICAL_FROM_VIRTUAL_MEMORY
Definition RequestStructures.h:506
@ SEARCH_PHYSICAL_MEMORY
Definition RequestStructures.h:504
@ SEARCH_VIRTUAL_MEMORY
Definition RequestStructures.h:505
#define SIZEOF_DEBUGGER_SEARCH_MEMORY
Definition RequestStructures.h:496
_Use_decl_annotations_ VOID SwitchToPreviousProcess(CR3_TYPE PreviousProcess)
Switch to previous process's cr3.
Definition SwitchLayout.c:125
_Use_decl_annotations_ CR3_TYPE SwitchToProcessMemoryLayoutByCr3(CR3_TYPE TargetCr3)
Switch to another process's cr3.
Definition SwitchLayout.c:99
_Use_decl_annotations_ CR3_TYPE SwitchToProcessMemoryLayout(UINT32 ProcessId)
Switch to another process's cr3.
Definition SwitchLayout.c:25
CR3 Structure.
Definition BasicTypes.h:130
UINT32 CountOf64Chunks
Definition RequestStructures.h:533
DEBUGGER_SEARCH_MEMORY_BYTE_SIZE ByteSize
Definition RequestStructures.h:532
DEBUGGER_SEARCH_MEMORY_TYPE MemoryType
Definition RequestStructures.h:531