File size: 65,272 Bytes
8739cbb | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 | --UEInfoScanner and UEInfoStructureDissect are licensed under the MIT License by Eric Heijnen / Cheat Engine
--https://github.com/cheat-engine/UnrealEngineTools
local function log(str)
if UEngine==nil then
UEngine={}
UEngine.processid=getOpenedProcessID()
end
if UEngine.log==nil then
UEngine.log=''
end
UEngine.log=UEngine.log..str..'\n\r'
end
function UObject_getName(UObjectAddress)
if UEngine==nil or UEngine.UObject==nil or UEngine.UObject.Name==nil or UEngine.IndexToName==nil then
return nil,'UEngine.UObject.Name not initialized yet'
end
--make sure it's an UObject. e.g UField is, but FField is not
local vftableptr=readPointer(UObjectAddress)
if vftableptr and vftableptr>=getAddress(process) and vftableptr<getAddress(process)+getModuleSize(process) then
local i=readQword(UObjectAddress+UEngine.UObject.Name)
local index=i & 0xffffffff
local number=i >> 32
local name=UEngine.IndexToName[i&0xffffffff]
if name and number>0 then
name=name..'_'..number
end
return name
end
end
function UObject_enumProperties(address)
local class=readPointer(address+UEngine.UObject.Class)
if class then
return UClass_enumProperties(class)
else
return nil,'Failure to read class field'
end
end
function UClass_enumProperties(class,usealt,r)
--get the parent fields as well? (remove duplicates)
if not r then
r={}
end
if UEngine.UClass.SuperStruct then
local super=readPointer(class+UEngine.UClass.SuperStruct)
if super then
UClass_enumProperties(super,usealt,r)
end
end
local p
if not usealt then
p=readPointer(class+UEngine.UClass.PropertyLink)
end
if p==nil or p==0 then
--maybe time to swap
p=readPointer(class+UEngine.UClass.PropertyLinkAlt)
end
if p and p~=0 then
while p and p~=0 do
e={}
local v=readInteger(p+UEngine.FProperty.Name)
local name=UEngine.IndexToName[v]
if v and name then
local offset=readInteger(p+UEngine.FProperty.Offset)
e.offset=offset
e.propertyAddress=p
local c=readPointer(p+UEngine.FProperty.Class)
if c==nil then
return nil,'c was nil'
end
local nameIndex=readInteger(c+UEngine.FFieldClass.Name)
if nameIndex==nil then
return nil,'nameIndex==nil'
end
e.propertyType=UEngine.IndexToName[nameIndex]
if UEngine.FProperty.Size then
e.size=readInteger(p+UEngine.FProperty.Size)
end
r[name]=e --override even if it existed
end
p=readPointer(p+UEngine.FProperty.PropertyLinkNext)
end
return r
else
return nil,'No propertylink found'
end
end
function getSuperListFromField(FieldAddress)
if isVTable(readPointer(FieldAddress)) then
local Names={}
local nameindex=readQword(FieldAddress+UEngine.FField.Name)
local name=UEngine.IndexToName[nameindex]
if name then
local class=readPointer(FieldAddress+UEngine.FField.Class)
while class and class~=0 do
nameindex=readQword(class+UEngine.FFieldClass.Name)
if nameindex==nil then return nil end
name=UEngine.IndexToName[nameindex]
if name==nil then return nil end
table.insert(Names,name)
class=readPointer(class+UEngine.FFieldClass.SuperClass)
end
return Names
end
end
end
function testIfSuperStructOffset(classAddress, offset)
local depth=0
local super={}
local class=readPointer(classAddress+offset)
while class and (class~=0) do
local n=UObject_getName(class)
if n then
table.insert(super, n)
else
return nil --a bad classname
end
local newclass=readPointer(class+offset)
if newclass==class then return nil end --points to itself (found Class, needed SuperClass)
class=newclass
depth=depth+1
if depth>20 then return nil end --endless loop
end
return super
end
function getSuperListFromObject(ObjectAddress)
--get the class
local super={}
local class=readPointer(ObjectAddress+UEngine.UObject.Class)
while class and class~=0 do
local n=UObject_getName(class)
if n then table.insert(super, n)
else
return nil --a bad classname
end
class=readPointer(class+UEngine.UClass.SuperStruct)
end
return super
end
function GetLinkedListSize(p,LinkOffset)
local c=0
repeat
p=readPointer(p+LinkOffset)
if p and p~=nil and p~=0 then
c=c+1
end
until p==nil or p==0 or c>100000
return c
end
function UEngine_findStructureStart(address)
address=address & 0xfffffffffffffff8
c=0
while c<100 do
local p=readPointer(address)
if p==nil then
return nil,'encountered unreadable memory'
end
if isVTable(p) then
return address
end
address=address-8
c=c+1
end
end
function findGameInstanceFPropertyAndFields(t)
--note: in older UE games a property is an UObject
if not UEngine.UGameEngine then return nil,'Find UGameEngine and GameEngineClass first' end
if not UEngine.GameEngineClass then return nil,'Find the GameEngineClass first' end
local index=UEngine.NameToIndex['GameInstance']
local ms=createMemScan() --todo: make aobscanarrays (multiple) allow multiple results
ms.VarType=vtQword
ms.ScanValue=index
ms.Fastscanmethod=fsmAligned
ms.Fastscanparameter=4
log('scanning GameInstance')
ms.scan()
local r=ms.Results
local errstr=ms.ErrorString
ms.destroy()
ms=nil
if errstr~='' then
return nil,errstr
end
if #r==0 then
return nil,'Failure finding references to the GameInstance FProperty'
end
local goodrangestart=getAddress(process)
local goodrangestop=getAddress(process)+getModuleSize(process)
local bases={}
local nameoffsets={} --to verify
for i=1,#r do
--find the structure start of each result, if possible (look up to 10 pointers back for a vtable, but keep in mind there can be more)
local base=UEngine_findStructureStart(r[i]) --scan for a vftable. a vftable is a pointer to a list in the module, and each pointer in that list is a pointer to an executable address (doesn't have to be .text)
if base then
table.insert(bases,base)
table.insert(nameoffsets,r[1]-base)
end
end
--now scan these bases for a pointer to GameEngineClass. Likely the offset will be close to the base as it's also in FField (lowest offset wins if multiple matches)
local FPropertyOwnerOffset
local GameInstanceFProperty
for i=1,#bases do
for j=1,32 do
if readPointer(bases[i]+j*8) & 0xfffffffffffffff0==UEngine.GameEngineClass then --ue 4.26 and 5 (UE5 used the lowest bits to set if it's an Object or Field, 4.26 used a byte with padding.
if FPropertyOwnerOffset then
if FPropertyOwnerOffset>j*8 then
FPropertyOwnerOffset=j*8
GameInstanceFProperty=bases[i]
end
else
FPropertyOwnerOffset=j*8
GameInstanceFProperty=bases[i]
end
break
end
end
end
if GameInstanceFProperty then
--found it!
--parse it for some useful stuff
UEngine.FProperty={}
UEngine.FProperty.Owner=FPropertyOwnerOffset
local potentialPropertyLists={} --FProperties have multiple lists
for i=1,64 do
local p=GameInstanceFProperty+i*4
local pp=readPointer(p)
local pi=pp & 0xffffffff
if isVTable(pp) then
break --another object starts here
end
if UEngine.FProperty.Name==nil then
if pi==index then
UEngine.FProperty.Name=i*4
end
end
if (UEngine.FProperty.Offset==nil) and (pi>8) and (pi<0x9000) and ((pi & 7) == 0) then --could be an offset to GameInstance
local potentialGameInstanceObject=readPointer(UEngine.UGameEngine+pi)
local name=UObject_getName(potentialGameInstanceObject)
if name then
--at least it has a name, check if it inherits from GameInstance
local superlist=getSuperListFromObject(potentialGameInstanceObject)
if superlist then
for j=1,#superlist do
if superlist[j]=='GameInstance' then
UEngine.FProperty.Offset=i*4
end
end
end
end
end
if (i & 0x1==0) and (pp & 0x7==0) then --pointer alignment
if UEngine.FProperty.Class==nil then --check if it's a FObjectProperty Class
--scan it for a name ending with Property (spoiler, it's ObjectProperty)
for j=0,16 do
local v=readQword(pp+j*4)
local n=UEngine.IndexToName[v]
if n then
if n:endsWith('Property') then
UEngine.FProperty.Class=i*4 --handy for validating future FProperties
UEngine.FFieldClass={}
UEngine.FFieldClass.Name=j*4
break
end
end
end
if UEngine.FProperty.Class and UEngine.FFieldClass.Name then --found the class just not.
--find SuperClass in FFieldClass (SuperClass is the same type as FFieldClass, so name is in the same spot)
local pf=readPointer(GameInstanceFProperty+UEngine.FProperty.Class)
for j=0,16 do
local v=readPointer(pf+j*8)
if v then
local v2=ReadQword(v+UEngine.FFieldClass.Name)
if v2 then
local name=UEngine.IndexToName[v2]
if name and (name:endsWith('Property') or name:endsWith('PropertyBase') or name=='Field') then
UEngine.FFieldClass.SuperClass=j*8 --found it
break
end
end
end
end
end
end
table.insert(potentialPropertyLists, i*4) --to be checked against name, and propertyclass later
end
end
if UEngine.FProperty and UEngine.FFieldClass and UEngine.FFieldClass.Name and UEngine.FProperty.Class and UEngine.FProperty.Name and UEngine.FProperty.Owner then
--now process the potentialPropertyLists. We have enough FProperty field info to determine if it's validish or not. Some of them are meh, and some of them contain everything including super class properties
--...
UEngine.FField={}
UEngine.FField.Class=UEngine.FProperty.Class
UEngine.FField.Owner=UEngine.FProperty.Owner
UEngine.FField.Name=UEngine.FProperty.Name
local PropertyLinkNextOffset
local BestPropertyCount
for i=1,#potentialPropertyLists do
--scan, but stop when a vtable is encountered (most properties are allocated next to eachother)
local p=readPointer(GameInstanceFProperty+potentialPropertyLists[i])
local superlist=getSuperListFromField(p) --handle P as a field
--UE5 : Property->Field (Done)
--UE4 : Property->Field->Object
if superlist and (
((#superlist>=2) and (superlist[#superlist]=='Field') and (superlist[#superlist-1]=='Property'))
or
((#superlist>=3) and (superlist[#superlist]=='Object') and (superlist[#superlist-1]=='Field') and (superlist[#superlist-2]=='Property'))
)
then
local c=GetLinkedListSize(GameInstanceFProperty, potentialPropertyLists[i])
if PropertyLinkNextOffset==nil or c>BestPropertyCount then
PropertyLinkNextOffset=potentialPropertyLists[i]
BestPropertyCount=c
end
end
end
UEngine.FProperty.PropertyLinkNext=PropertyLinkNextOffset
--scan the GameEngineClass for properties (todo: maybe also add a few others)
local PropertyLinkOffset
BestPropertyCount=0
local altoffset
for i=1,100 do
local p=readPointer(UEngine.GameEngineClass+i*8)
if isVTable(p) then break end
local superlist=getSuperListFromField(p)
if superlist and (
((#superlist>=2) and (superlist[#superlist]=='Field') and (superlist[#superlist-1]=='Property'))
or
((#superlist>=3) and (superlist[#superlist]=='Object') and (superlist[#superlist-1]=='Field') and (superlist[#superlist-2]=='Property'))
)
then
local c=GetLinkedListSize(p, UEngine.FProperty.PropertyLinkNext)
if PropertyLinkOffset==nil or c>=BestPropertyCount then
altoffset=PropertyLinkOffset
PropertyLinkOffset=i*8
BestPropertyCount=c
end
end
end
UEngine.UClass.PropertyLink=PropertyLinkOffset
UEngine.UClass.PropertyLinkAlt=altoffset
--find some property specific info (Property size field, and for BoolProperty the bitfields (01 00 bitmask bitmask for properties that have the same offset)
local gameEngineProperties=UClass_enumProperties(UEngine.GameEngineClass)
local sizes={}
sizes[1]={}
sizes[4]={}
sizes[8]={}
local bools={}
for name, info in pairs(gameEngineProperties) do
if info.propertyType=='FloatProperty' then
if #sizes[4]<10 then
table.insert(sizes[4],info.propertyAddress)
end
elseif info.propertyType=='IntProperty' then
if #sizes[4]<10 then
table.insert(sizes[4],info.propertyAddress)
end
elseif info.propertyType=='ObjectProperty' then
if #sizes[8]<10 then
table.insert(sizes[8],info.propertyAddress)
end
elseif info.propertyType=='ClassProperty' then
if #sizes[8]<10 then
table.insert(sizes[8],info.propertyAddress)
end
elseif info.propertyType=='BoolProperty' then
if #sizes[1]<10 then
table.insert(sizes[1],info.propertyAddress)
end
if bools[info.offset]==nil then
bools[info.offset]={}
end
table.insert(bools[info.offset], info.propertyAddress)
end
end
for i=2,64 do
local foundsize=true
for size,addresslist in pairs(sizes) do
for j=1,#addresslist do
if readInteger(addresslist[j]+i*4)~=size then
foundsize=false
break
end
end
if foundsize==false then break end
end
if foundsize then
UEngine.FProperty.Size=i*4
break
end
end
--now try to find the bitfields
local multibitfields={}
local couldbefullbyte=false
for offset,addresslist in pairs(bools) do
if #addresslist>1 then
table.insert(multibitfields,addresslist) --guaranteed to have 1 bit sized entries
end
end
if #multibitfields==0 then
--bah, it's all single bit fields... Just use these then
couldbefullbyte=true
for offset,addresslist in pairs(bools) do
table.insert(multibitfields,addresslist)
end
end
local startIndex=UEngine.FProperty.PropertyLinkNext // 8+1 --it starts after the normal property definition (
local isSingleBit={}
isSingleBit[1]=true
isSingleBit[2]=true
isSingleBit[4]=true
isSingleBit[8]=true
isSingleBit[16]=true
isSingleBit[32]=true
isSingleBit[64]=true
isSingleBit[128]=true
for i=startIndex,64 do
local foundbitmaskfield=true
for j=1,#multibitfields do
for k=1,#multibitfields[j] do
local v=readInteger(multibitfields[j][k]+i*4)
local b1=v & 0xff
if b1~=1 then
foundbitmaskfield=false
break
end
local b2=(v >> 8) & 0xff
if b2~=0 then
foundbitmaskfield=false
break
end
local b3=(v >> 16) & 0xff;
if not isSingleBit[b3] then
if (couldbefullbyte==false) or (b3~=0xff) then
foundbitmaskfield=false
break
end
end
local b4=(v >> 24) & 0xff;
if not isSingleBit[b4] then
if (couldbefullbyte==false) or (b4~=0xff) then
foundbitmaskfield=false
break
end
end
end
if foundbitmaskfield==false then break end
end
if foundbitmaskfield then
UEngine.FProperty.BitMaskField=i*4
UEngine.FProperty.ObjectClassType=i*4 --same offset (e.g ObjectClassType for the property GameInstance is a pointer to the GameInstanceClass
break
end
end
--Obtained everything needed
return true, 'success'
else
return nil,'Not all needed fields where found'
end
else
return nil, 'Failed finding GameInstanceFProperty'
end
return nil,'huh?'
end
function FindGEngine(t)
--some options: Parse the whole object table , or signature scan. Trying the sigscan method first as it can be done without injection
if UEngine.UObject.Name==nil then
return nil,'UEngine.UObject.Name==nil'
end
local index=UEngine.NameToIndex['GameEngine']
--local altindex=UEngine.NameToIndex['OakGameEngine'] --alternate option (inherits from gameengine)
if index==nil then return false, "failure finding GameEngine string" end
local ms=createMemScan()
local start,stop
mstart=getAddress(process)
mstop=mstart+getModuleSize(process)
ms.VarType=vtGrouped
ms.Fastscanmethod=fsmAligned
ms.Fastscanparameter=8
-- ms.Scanvalue='p:S w:'..(UObject.Name-8)..' 4:'..NameToIndex['OakGameEngine']
--ms.Scanvalue='p:S w:'..(UObject.Name-8)..' 4:'..NameToIndex['GameEngine']
--doing a range scan is faster that a p:S scan
ms.Scanvalue='8r:'..mstart..'-'..mstop..' w:'..(UEngine.UObject.Name-8)..' 4:'..UEngine.NameToIndex['GameEngine']
ms.ScanWritable='scanInclude'
ms.ScanExecutable='scanExclude'
ms.ScanCopyOnWrite='scanExclude'
ms.scan()
log('FindGEngine: Starting scan for '..ms.Scanvalue)
ms.waitTillDone()
log('FindGEngine: Scan finished')
sleep(1000)
ms.nextScan()
local r=ms.Results
local r2
if t and t.terminated then return nil end
ms.destroy()
ms=nil
log('FindGEngine: Next scan finished')
if #r>=1 then
r2={}
for i=1,#r do
if isVTable(readPointer(r[i])) then
--todo: check classname for the name 'GameEngine' which itself has a classname of 'Class' (or the Superclasses named Engine->Object->nil pointer
--still here
table.insert(r2,r[i])
end
end
end
r={}
for i=1,#r2 do
--the instantiated GEngine has a number for the name
if readInteger(r2[i]+UEngine.UObject.Name+4)~=0 then table.insert(r,r2[i]) end
end
if #r>1 then
return nil,'FindGEngine needs more refining'
end
if #r==0 then
log('FindGEngine: No direct GEngine found')
--no instance found, maybe it created a subclass
if #r2>=1 then
log('Searching deeper')
for gei=1,#r2 do
local PotentialGameEngineClass=r2[gei]
--there is GameEngine , likely a GameEngine Class (Confirm by checking the class pointer name to be 'Class')
--printf("subclass situation")
local ClassClass=readPointer(r2[1]+UEngine.UObject.Class) --should be the default 'Class' Object
if isVTable(readPointer(ClassClass))==false then
goto continue
--return nil,'Invalid ClassClass'
end
local ClassClassName=UObject_getName(ClassClass)
if ClassClassName~='Class' then
goto continue
--return nil,'ClassClass type is not a class'
end
--still here, so this is indeed the gameengine class
--find the superclass pointer which has the name "Engine" (need to know the offset for the scan already)
if UEngine.UClass==nil then
UEngine.UClass={}
UEngine.UClass.Name=UEngine.UObject.Name
UEngine.UClass.Class=UEngine.UObject.Class
end
for i=1,32 do
local n=UObject_getName(readPointer(PotentialGameEngineClass+i*8)) --0x40 in borderlands 4
if n=='Engine' then
--found the superstruct
UEngine.UClass.SuperStruct=i*8
break
end
end
--find the class that has the GameEngineClass as it's superstruct
if UEngine.UClass.SuperStruct==nil then
goto continue
-- return nil,'UClass.SuperStruct==nil'
end
local ms=createMemScan()
ms.VarType=vtGrouped
ms.Fastscanmethod=fsmAligned
ms.Fastscanparameter=8
--build a scanstring
local sv='BA:8 8r:'..mstart..'-'..mstop
local offset=8
if UEngine.UClass.Class<UEngine.UClass.SuperStruct then
sv=sv..' w:'..UEngine.UClass.Class-offset..' 8:'..ClassClass
offset=UEngine.UClass.Class+8
sv=sv..' w:'..UEngine.UClass.SuperStruct-offset..' 8:'..PotentialGameEngineClass
else --it theoretically 'could' happen with enough customization fuckery
sv=sv..' w:'..UEngine.UClass.SuperStruct-offset..' 8:'..PotentialGameEngineClass
offset=UEngine.UClass.SuperStruct+8
sv=sv..' w:'..UEngine.UClass.Class-offset..' 8:'..ClassClass
end
ms.Scanvalue=sv --'p:S w:'..(UClass.SuperStruct-8)..' 8:'..PotentialGameEngineClass
ms.ScanWritable='scanInclude'
ms.ScanExecutable='scanExclude'
ms.ScanCopyOnWrite='scanExclude'
ms.scan()
ms.waitTillDone()
ms.nextScan()
r=ms.Results
ms.destroy() ms=nil
local found=false
--all potential classes that have inherited from GameEngine (likely just 1)
for i=1,#r do
--find all objects that have this as class --todo: may have to go deeper (in which case an object enum might be faster)
local ms=createMemScan()
ms.VarType=vtGrouped
ms.Fastscanmethod=fsmAligned
ms.Fastscanparameter=8
ms.Scanvalue='BA:8 8r:'..mstart..'-'..mstop..' w:'..(UEngine.UClass.Class-8)..' 8:'..r[i] --the address of the class at the class offset.
ms.ScanWritable='scanInclude'
ms.ScanExecutable='scanExclude'
ms.ScanCopyOnWrite='scanExclude'
log('scanning for '..ms.Scanvalue)
ms.scan()
r2=ms.Results
ms.destroy() ms=nil
r3={}
for j=1,#r2 do
--check if the name number if set
--the instantiated GEngine has a number for the name
if readInteger(r2[j]+UEngine.UObject.Name+4)~=0 then table.insert(r3,r2[j]) end
end
if #r3>0 then
r=r3
found=true
GameEngineClass=PotentialGameEngineClass
break
end
end
if found then
break
end
::continue::
end
else
return false,'No GameEngine found'
end
end
if #r==0 then
return nil,'No GameEngine instance found'
end
UEngine.UGameEngine=r[1]
--GameEngine is found , lets try to find GEngine while we're (handy when the game restarts)
ms=createMemScan()
ms.VarType=vtQword
ms.ScanValue=UEngine.UGameEngine
ms.Startaddress=getAddress(process)
ms.Stopaddress=getAddress(process)+getModuleSize(process)
ms.scan()
r=ms.Results
if #r==1 then
UEngine.GEngine=r[1]
unregisterSymbol('GEngine')
local n=getNameFromAddress(UEngine.GEngine,true,false,false)
if n:find(extractFileNameWithoutExt(process)) then
registerSymbol('GEngine',getNameFromAddress(UEngine.GEngine), true)
end
end
ms.destroy()
return true
end
function isInExecutableMainModuleMemory(address)
if UEngine.ExecutableRanges==nil then
UEngine.ExecutableRanges={}
--alternatively, I could init the range by using the first UObjectList's first pointer and follow it to a executable code. Works for each list type as the first item is always a pointer
if UEngine.VFTableInExecutableMemoryMethod==nil or UEngine.VFTableInExecutableMemoryMethod==2 then
--method 1/nil: First executable code section
--method 2: All executable code sections
local sections=enumSectionsOfModule(process)
--find the first executable section
for i=1,#sections do
if sections[i].IsCode and sections[i].IsExecutable then
local e={}
e.start=sections[i].Address
e.stop=sections[i].Address+sections[i].Size
table.insert(UEngine.ExecutableRanges,e)
if UEngine.VFTableInExecutableMemoryMethod==nil then
break
end
end
end
end
if #UEngine.ExecutableRanges==0 then
--worst case scenario
local goodrangestart=getAddress(process)
local goodrangestop=getAddress(process)+getModuleSize(process)
local executablePageProtect={}
executablePageProtect[PAGE_EXECUTE]=true
executablePageProtect[PAGE_EXECUTE_READ]=true
executablePageProtect[PAGE_EXECUTE_READWRITE]=true
executablePageProtect[PAGE_EXECUTE_WRITECOPY]=true
local mr=enumMemoryRegions()
for i=1,#mr do
if executablePageProtect[mr[i].Protect] and (mr[i].BaseAddress>=goodrangestart) and (mr[i].BaseAddress+mr[i].RegionSize<goodrangestop) then
local e={}
e.start=mr[i].BaseAddress
e.stop=mr[i].BaseAddress+mr[i].RegionSize
table.insert(UEngine.ExecutableRanges,e)
end
end
end
end
local er=UEngine.ExecutableRanges
for i=1,#er do
if address>er[i].start and address<er[i].stop then
return true
end
end
return false
end
function isVTable(address)
if address==nil then return nil,'invalid address' end
local goodrangestart=getAddress(process)
local goodrangestop=getAddress(process)+getModuleSize(process)
if address>goodrangestart and address<goodrangestop then
--check if it's a list of pointers to functions
for i=0,8 do
local p=readPointer(address+i*8)
if isInExecutableMainModuleMemory(p)==false then
return false
end
end
return true
else
return false;
end
end
function InitializeUObjectArray_Verifier_Type()
if UObjectArray_Verifier_Type then
UObjectArray_Verifier_Type.destroy()
end
UObjectArray_Verifier_Type=getCustomType('UObjectArray Verifier Type')
if UObjectArray_Verifier_Type then
UObjectArray_Verifier_Type.destroy()
end
UObjectArray_Verifier_Type=nil
UObjectArray_Verifier_Type,emsg=registerCustomTypeAutoAssembler([[{$c}
//returns 1 if the type matches
char TypeName[]="UObjectArray Verifier Type";
int ByteSize=16;
char CallMethod=1; //cdecl
int PreferedAlignment=0x10;
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
typedef struct
{
int val1;
int val2;
int val3;
int zero;
} *pdata;
__cdecl size_t ConvertRoutine(pdata data, unsigned long long address)
{
int r=1;
//if (data->val1<100) return 0; //no tiny games
if (data->zero) return 0;
if (data->val3!=data->val1) return 0;
if ((data->val2) != ((data->val1)-1)) return 0;
//still here
return 1;
}
__cdecl void ConvertBackRoutine(size_t input, unsigned long long address, unsigned char *output)
{
//nope
}
{$asm}]])if UObjectArray_Verifier_Type==nil and emsg then
error(emsg)
end
UObjectArray_Verifier_Type.InternalOnly=true
end
function FindObjectArray(t) --and UObject name offset
--for 4.26 >
local r={}
if UObjectArray_Verifier_Type==nil then
InitializeUObjectArray_Verifier_Type()
if UObjectArray_Verifier_Type==nil then
return nil,'No verifier type'
end
end
if UEngine.ObjectArray==nil then
local ms=createMemScan()
ms.VarType=vtGrouped --custom type only also works
ms.Fastscanmethod=fsmAligned
ms.Fastscanparameter=10
ms.Scanvalue='BA:8 c(UObjectArray Verifier Type):1 p:D'
ms.Startaddress=getAddress(process)
ms.Stopaddress=getAddress(process)+getModuleSize(process)
ms.scan()
ms.waitTillDone()
r=ms.Results
local errorstring=ms.ErrorString
ms.destroy()
ms=nil
if t and t.Terminated then return false, 'UEInfoScannerThread terminated' end
if #r==0 then
return false,'Failed finding anything ('..errorstring..')'
end
if #r>1 then
local r2={}
--find the ones with
for i=1,#r do
if (readInteger(r[i])==0) or (readInteger(r[i])>100) then
table.insert(r2,r[i])
end
end
r=r2
if #r>1 then
r2={}
for i=1,#r do
if readInteger(r[i])>100 then
table.insert(r2,r[i])
end
end
r=r2
r2={}
--check if the first pointer pointed at is valid (there are currently 2 known types. Both both have a pointer at the first entry)
for i=1,#r do
local p=readPointer(r[i]+0x10)
if p and readPointer(readPointer(p)) then
table.insert(r2,r[i])
end
end
r=r2
if #r>1 then
--more refining needed. (pick the one with the highest value or a deeper inspection of the array list)
return false,'Needs more refining',r
end
end
end
else
r={}
r[1]=UEngine.ObjectArray
end
if t and t.Terminated then return false, 'UEInfoScannerThread terminated' end
if #r==1 then
UEngine.ObjectArray=r[1]
--figure out some stuff
local p=readPointer(UEngine.ObjectArray+0x10)
if p then
--get the first block
--test what type of list this is. pointer list, or a (huge) list of ObjectArray entries
if readByte(readPointer(p)) and readByte(readPointer(p+8)) then
UEngine.ObjectArrayListType=0 --list of sequential pointers to ObjectArray entries
p=readPointer(p) --p now points to the first object array entry
else
--list of Object entries (or the list is just 1 long. Maybe launched too soon?)
UEngine.ObjectArrayListType=1
--check some more things, maybe it is just a short list
local ObjectListAddress=readPointer(p)
local FirstObject=readPointer(ObjectListAddress)
local vftable=readPointer(FirstObject)
if vftable then
local f1,f2,f3=readPointer(vftable), readPointer(vftable+8), readPointer(vftable+16)
if isInExecutableMainModuleMemory(f1) and isInExecutableMainModuleMemory(f2) and isInExecutableMainModuleMemory(f3) then
--3 valid pointers to executable memory. Guess it's just a small list (single)
UEngine.ObjectArrayListType=0
p=ObjectListAddress
end
end
end
local goodrangestart=getAddress(process)
local goodrangestop=getAddress(process)+getModuleSize(process)
--find the vtable executable section, take the first pointer (for now assume that the first entry of a structure is a pointer)
local sections=enumSectionsOfModule(process)
local object1=readPointer(p)
local vftable=readPointer(object1)
local firstfunctionaddress=readPointer(vftable) --get the address of the first function pointed at in the vftable
for i=1,#sections do
if firstfunctionaddress>=sections[i].Address and firstfunctionaddress<sections[i].Address+sections[i].Size then
if sections[i].IsCode and sections[i].IsExecutable then
--valid. Use this as a template for all future vtable rules (if not, then try the other methods described later)
UEngine.ExecutableRanges={}
UEngine.ExecutableRanges[1]={}
UEngine.ExecutableRanges[1].start=sections[i].Address
UEngine.ExecutableRanges[1].stop=sections[i].Address+sections[i].Size
end
break
end
end
local validpointers={}
--figure out the ObjectArray entry size
for i=0,32 do
local p1=readPointer(p+(i*4)) --scan through the block in chunks of 8
local pv=readPointer(p1)
if isVTable(pv) then --first time relying on isVTable. It can bug out so deal with it if needed
--found a valid pointer
table.insert(validpointers, (i*4))
end
end
if #validpointers==0 then
--fallback on all executable code sections
UEngine.VFTableInExecutableMemoryMethod=2
UEngine.ExecutableRanges=nil
for i=0,32 do
local p1=readPointer(p+(i*4))
local pv=readPointer(p1)
if isVTable(pv) then
--found a valid pointer
table.insert(validpointers, (i*4))
end
end
if #validpointers==0 then
--fall back on all executable memory in the module
UEngine.VFTableInExecutableMemoryMethod=3
UEngine.ExecutableRanges=nil
for i=0,32 do
local p1=readPointer(p+(i*4))
local pv=readPointer(p1)
if isVTable(pv) then --first time relying on isVTable. It can bug out so deal with it if needed
--found a valid pointer
table.insert(validpointers, (i*4))
end
end
end
end
if #validpointers<=1 then
return false,"can't find figure out ObjectArrayEntryStruct size"
end
UEngine.ObjectArrayEntryStructSize=validpointers[2]-validpointers[1]
--try to figure out the name offset now we're here
--if IndexToName[0] and IndexToName[1] and IndexToName[2] then --findValidFNameFieldOffsetsInMemory won't work well here
--instead, try to find the pointer to UClass and find the string to class
--to find the class pointer find a pointer that points to itself eventually. it's name will be "Class" (class->class->class->class->....)
--note: Object0 tends to be /Script/CoreUObject
local classPointerOffsetCount={}
local nameoffsetcount={}
local ClassNameIndex=UEngine.NameToIndex['Class']
if ClassNameIndex==nil then
return false,'There is no Class class'
end
for i=1,#validpointers do
local objectaddress=readPointer(p+validpointers[i])
for j=1,10 do
local ep=readPointer(objectaddress+j*8)
local depth=0
while depth<20 do
local newp=readPointer(ep+j*8)
if newp==nil then break end
if newp==ep then
local hasClassIndex=false
--possible class pointer found
--find the classindex in here
for k=2,20 do --+2 to skip the vtable
local index=readInteger(ep+k*4)
if index==ClassNameIndex then
hasClassIndex=true
if nameoffsetcount[k*4] then
nameoffsetcount[k*4]=nameoffsetcount[k*4]+1
else
nameoffsetcount[k*4]=1
end
end
end
if hasClassIndex then
if classPointerOffsetCount[j*8] then
classPointerOffsetCount[j*8]=classPointerOffsetCount[j*8]+1
else
classPointerOffsetCount[j*8]=1
end
end
break
end
ep=newp
depth=depth+1
end
end
end
local highestcount=0
local bestoffset=nil
for offset,count in pairs(classPointerOffsetCount) do
if count>highestcount then
bestoffset=offset
highestcount=count
end
end
UEngine.UObject={}
UEngine.UObject.Class=bestoffset
highestcount=0
bestoffset=nil
for offset,count in pairs(nameoffsetcount) do
if count>highestcount then
bestoffset=offset
highestcount=count
end
end
UEngine.UObject.Name=bestoffset
end
return true
end
end
function SetupNamePoolLookupType()
--handy for structure dissect
if getCustomType('UE FName to String')==nil then
local function customvaluetype2_bytestovalue(b1,b2,b3,b4,b5,b6,b7,b8,address)
local v1
v1=(b4 << 24) + (b3<<16) + (b2 << 8) + b1
v2=(b8 << 24) + (b7<<16) + (b6 << 8) + b5
if UEngine and UEngine.IndexToName then
local n=UEngine.IndexToName[v1]
if n==nil then
n='<noname>'
end
if v2>0 then
return string.format("%s_%d",n,v2)
else
return n
end
else
return 'noindex'
end
end
local function customvaluetype2_valuetobytes(i,address)
--maybe use StringToFName, but for now I see no reason for this
end
synchronize(function()
registerCustomTypeLua('UE FName to String',8,customvaluetype2_bytestovalue, customvaluetype2_valuetobytes, false,true )
end)
end
end
function CacheNamePool_old()
log('CacheNamePool_old')
if UEngine.NamePoolData==nil then return nil,'UEngine.NamePoolData not defined yet' end
local N2I={}
local I2N={}
--copy and parse all the strings
--each block is 0x20000 bytes long
--the list ends with a NULL pointer
local sdata=createMemoryStream()
sdata.Size=0x20000
local count=1000
local pointerlist=createMemoryStream()
pointerlist.Size=8*count
if copyMemory(UEngine.NamePoolData,pointerlist.Size, pointerlist.Memory,1)==nil then return nil,'Read Failed' end
local stringCache={} --read blocks of 0x40000 bytes (index is address >> 17)
local StringOffset=UEngine.FNameEntry.String
for i=1,count do
local p=pointerlist.readQword()
if p==0 then break end
sdata.Position=0
--entrystart is always aligned on a 2 byte boundary.
if copyMemory(p,sdata.Size, sdata.Memory,1) then
for j=0,16383 do
--list of pointers, some can be 0
local p2=sdata.readQword()
if p2==nil then break end
if p2~=0 then
--get the memory p+StringOffset points to
local Base=p2&0xFFFFFFFFFFFF0000 --allocation granularity of windows
local cache=stringCache[Base]
if cache==nil then
cache=createMemoryStream()
local meminfo=getMemoryRegionInfo(Base)
if meminfo and meminfo.State==4096 then --4096 is commited memory
while meminfo.RegionSize<0x10000+0x100 do --0x100 for overlap
local n=getMemoryRegionInfo(meminfo.BaseAddress+meminfo.RegionSize)
if n and n.State==4096 then
meminfo.RegionSize=meminfo.RegionSize+n.RegionSize
else
break
end
end
if meminfo.RegionSize>0x10000+0x100 then
meminfo.RegionSize=0x10000+0x100
end
cache.Size=meminfo.RegionSize
if copyMemory(Base,meminfo.RegionSize, cache.Memory,1)==nil then
cache.Size=0
end
end
stringCache[Base]=cache --c.size==0 is unreadable
end
local pindex=p2-Base+StringOffset
local sizeleft=cache.Size-pindex
local str
if sizeleft>0 then
cache.position=pindex
str=cache.readString(math.min(100,sizeleft))
end
if str then
local index=(i-1)*16384+j
N2I[str]=index
I2N[index]=str
end
end
end
end
-- print("done")
for base,ms in pairs(stringCache) do
if ms then
ms.destroy()
end
end
stringCache={}
-- printf("namelookupprogress=%.2f",namelookupprogress)
end
pointerlist.destroy()
sdata.destroy()
UEngine.NameToIndex=N2I
UEngine.IndexToName=I2N
return true
end
function CacheNamePool(t)
log('CacheNamePool')
--remember the comment at the top about debugging causing a slowdown? That particularly means this function right here
if UEngine.NamePoolData==nil then
return false, 'CacheNamePool: UEngine.NamePoolData is still undefined'
end
if UEngine.NamePoolData_old then
return CacheNamePool_old(t)
end
local N2I={}
local I2N={}
--copy and parse all the strings
--each block is 0x20000 bytes long
--NamePool+0x8 holds a 4 byte with the count. Alternatively, the list ends with a NULL pointer
local sdata=createMemoryStream()
sdata.Size=0x20000
local count=readInteger(UEngine.NamePoolData+8)
if count==0 then count=1000 end
local pointerlist=createMemoryStream()
pointerlist.Size=8*count
if copyMemory(UEngine.NamePoolData+0x10,pointerlist.Size, pointerlist.Memory,1)==nil then return nil,'Read Failed' end
for i=1,count do
if t and t.Terminated then
sdata.destroy()
pointerlist.destroy()
return false, 'UEInfoScannerThread terminated'
end
local p=pointerlist.readQword()
if p==0 then break end
sdata.Position=0
--entrystart is always aligned on a 2 byte boundary.
if copyMemory(p,sdata.Size, sdata.Memory,1) then
while sdata.Position<sdata.Size do
local entrystart=sdata.Position >> 1
local header=sdata.readWord()
local iswide=header & 1==1
local len=header >> 6
if len==0 then break end
local str
if iswide then
str=sdata.readWideString(len)
else
str=sdata.readString(len)
end
local index=((i-1) << 16)+entrystart
N2I[str]=index
I2N[index]=str
--symcount=symcount+1
if (sdata.Position & 1) == 1 then sdata.readByte() end --align
end
else
print("Failure reading strings")
end
end
pointerlist.destroy()
sdata.destroy()
UEngine.NameToIndex=N2I
UEngine.IndexToName=I2N
return true
end
function FindNamePoolData_older(t)
--[[
e.g 4.19: The occupation
FNameEntry is formatted as : index, FNameEntry (hash?), ascii string (None, ByteProperty, InrProperty, BoolProperty,...)
Each FnameEntry is pointed at by another block of memory of 0x20000 bytes (16384 pointers) to each individual string
and that list itself is pointed at by another one , which has a pointer to it from a memory addres in the game (Call it GNames)
example:
2454CB90000 = 0, pointer, "None"
2454CB90018 = 2, pointer, "ByteProperty"
apparently if the first bit is 1 the string is a WideString (rare)
address 2454B600000 holds 0x20000 bytes, all pointers. The first pointer points to 2454CB90000. There can be null pointers in that memory block
address 2454B5F0080 holds some(9 in this case) pointers as well. First pointer is 2454B600000 (block[0]=2454B600000, block[1]=2454B600008, block[2]=2454B600010)
Secondary for next run optimization:
There are 2 static pointers to 2454B5F0080
First one: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 "80 00 5F 4B 45 02 00 00" 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 3A A7 67 45 02 00 00 0A 00 00 00 18 00 00 00
Second one:00 00 00 00 00 00 00 00 00 00 00 00 88 00 00 80 "80 00 5F 4B 45 02 00 00" 40 00 5E 4B 45 02 00 00 01 00 00 00 00 00 00 00 09 00 00 80 00 00 00 00 00 00 00 00 00 00 00 00 00 00 36 D6 F6 7F 00 00 E3 36 EA 41 00 00 01 00 98 EF 1B D8 F6 7F 00 00
--]]
if UEngine.NamePoolData then return true end
UEngine.NamePoolData_old=true --todo: if more than 2 formats, change it to an identifier number
local ms=createMemScan()
ms.VarType=vtGrouped
ms.Scanvalue=[[BA:4096 BS:128 OOO:U 1:* s:'None' s:'ByteProperty']]
ms.scan()
firststringblock=ms.Results
ms.destroy()
if t and t.Terminated then
return false,'UEInfoScannerThread terminated'
end
if #firststringblock==0 then
return false,'No known stringpool found'
end
if #firststringblock>1 then
return false,'FindNamePoolData_older needs more refining'
end
--check the format
UEngine.FNameEntry={}
local a=firststringblock[1]
for i=0,128 do
if readString(a+i,4)=='None' then --find the first string offset
UEngine.FNameEntry.String=i
break
end
end
--find a pointer to this table (The pointer is not located in static memory)
ms=createMemScan()
ms.VarType=vtQword
ms.ScanValue=a
ms.FastScanMethod=fsmLastDigits
ms.FastScanparameter='0000' --the first pointer of a 0x20000 bytes long block, alliged
ms.scan()
local r=ms.Results
ms.destroy()
if t and t.Terminated then
return false,'UEInfoScannerThread terminated'
end
if #r==0 then return nil,'no list found' end
if #r>1 then return nil,'needs more refining' end
--check for a pointer to this address. Normally aligned. todo: if more than 1 result, check the following pointers if they point to other blocks of 0x20000 bytes all pointing to a FNameEntry or null
ms=createMemScan()
ms.VarType=vtQword
ms.ScanValue=r[1]
ms.FastScanMethod=fsmAligned
ms.FastScanparameter='8' --the first pointer of a 0x20000 bytes long block, alliged
ms.scan()
local r2=ms.Results
ms.destroy()
if #r2==0 then
return nil,'No list found'
end
if #r2>1 then
return nil,'todo: check other pointers for valid stringblocks'
end
UEngine.NamePoolData=r2[1]
return true
end
function FindNamePoolData(t)
if UEngine.NamePoolData then return true end --already found
--ue5
local ms=createMemScan()
ms.VarType=vtByteArray
ms.Hexadecimal=true
ms.Scanvalue='* 01 4e 6f 6e 65 * 03 42 79 74' --x None and x ByteProperty
ms.Fastscanmethod=fsmAligned
ms.Fastscanparameter=10000
--ms.Priority='tpIdle'
ms.scan()
while ms.waitTillDone(1000)==false do
if t and t.Terminated then
ms.terminateScan()
end
end
firststringblock=ms.results
ms.destroy() ms=nil --doing it on the same line so that single step debugging won't get corrupted by bad upvalue pointers
if t and t.Terminated then
return false,'UEInfoScannerThread terminated'
end
if #firststringblock==0 then
--maybe an older version
local r,err=FindNamePoolData_older()
return r,err
end
--find references to this address in the target process
local probablenamepools={}
local ms={}
for i=1,#firststringblock do
ms[i]=createMemScan()
ms[i].VarType=vtQword
ms[i].Fastscanmethod=fsmAligned
ms[i].Fastscanparameter=8
ms[i].Scanvalue=firststringblock[i]
ms[i].Startaddress=getAddress(process)
ms[i].Stopaddress=getAddress(process)+getModuleSize(process)
ms[i].scan()
end
r={}
for i=1,#firststringblock do
ms[i].waitTillDone()
local tr=ms[i].Results
for j=1,#tr do
table.insert(r,tr[j])
end
ms[i].destroy() ms[i]=nil
end
if t and t.Terminated then
return false,'UEInfoScannerThread terminated'
end
if #r>1 then
--the pointer after it points to another string list and before it looks like a number of strings and a number of pointers to stringlists
--the pointers it points to also have an allocation size of 0x20000
local r2={}
for i=1,#r do
local valid=true
for j=1,3 do
local a=readPointer(r[i]+j*8)
if a~=0 then --I don't think this version has empty pointers, but for now allow it
local mri=getMemoryRegionInfo(a)
if (mri==nil) or (mri.RegionSize~=0x20000) then
valid=false
break
end
end
end
if valid then
table.insert(r2,r[i])
end
end
r=r2
if #r>1 then
return false,'too many found. Needs more refining'
end
end
if #r==0 then
return false,'not found' --error
end
if #r==1 then
UEngine.NamePoolData = r[1] - 0x10 --todo: save this address for the next run
return true
end
end
function createUEMenu()
log('Creating menuitem')
synchronize(function()
if UEngine.GUI==nil then
UEngine.GUI={}
elseif UEngine.GUI.miUnrealEngine then
UEngine.GUI.miUnrealEngine.destroy()
UEngine.GUI.miUnrealEngine=nil
UEngine.GUI={} --clear everything under it
end
UEngine.GUI.miUnrealEngine=createMenuItem(MainForm)
UEngine.GUI.miUnrealEngine.Caption='Initializing Unreal Engine'
UEngine.GUI.miUnrealEngine.Name='miUnrealEngine'
UEngine.GUI.miStatus=createMenuItem(MainForm)
UEngine.GUI.miStatus.Name='miStatus'
UEngine.GUI.miStatus.Caption='Status'
UEngine.GUI.miStatus.OnClick=function()
if UEInfoScannerThread and (messageDialog('Cancel the Unreal Engine data collection?',mtConfirmation,mbYes, mbNo)==mrYes) then
UEInfoScannerThread.Terminate()
end
end
UEngine.GUI.miUnrealEngine.add(UEngine.GUI.miStatus)
UEngine.GUI.miHurry=createMenuItem(MainForm)
UEngine.GUI.miHurry.Name='miHurry'
UEngine.GUI.miHurry.Caption='Prioritize this'
UEngine.GUI.miHurry.OnClick=function()
if UEInfoScannerThread then
UEInfoScannerThread.Priority='tpHigher'
end
UEngine.GUI.miHurry.destroy()
UEngine.GUI.miHurry=nil
end
UEngine.GUI.miUnrealEngine.add(UEngine.GUI.miHurry)
MainForm.Menu.Items.insert(MainForm.miHelp.MenuIndex, UEngine.GUI.miUnrealEngine)
end)
end
function UEInfoScanner(t)
--can be called directly or with a thread
log('UEInfoScanner start');
local id=process..'-'..md5memory(getAddressSafe(process),4096)
local s=getSettings("UEInfo\\"..id,true)
local r
--get data from the registry if available
if t then
log('Threaded')
t.FreeOnTerminate(false)
t.Name='UEInfoScannerThread'
end
if UEngine==nil or UEngine.processid~=getOpenedProcessID() then
--start from scratch
if UEngineStructDissect then
unregisterStructureDissectOverride2(UEngineStructDissect)
UEngineStructDissect=nil
end
if UEngine.GUI then
if UEngine.GUI.miUnrealEngine then
UEngine.GUI.miUnrealEngine.destroy()
UEngine.GUI=nil
end
end
UEngine={}
UEngine.processid=getOpenedProcessID()
end
--[[
check the settings if everything has already been found, or if only a subset was found so far.
If only a subset, go through the whole thing, but if everything was found then load all from the registry, but still
go through the string cache system
--]]
if (s.fullyParsed) then
log('The state was fully parsed. Using this')
--load all fields and offsets
--load the UEngine data from the registry
local list=s.getValueList()
for name,value in pairs(list) do
if name:startsWith('UEngine.') then
local sections=table.pack(name:split('.'))
local t=UEngine
for i=2,#sections-1 do
local newt=t[sections[i]]
if newt==nil then
t[sections[i]]={}
newt=t[sections[i]]
end
t=newt
end
t[sections[#sections]]=tonumber(value)
end
end
--cache the namepool data
createUEMenu()
UEngine.NamePoolData=getAddressSafe(s.NamePoolData)
UEngine.ObjectArray=getAddressSafe(s.ObjectArray)
UEngine.GEngine=getAddressSafe(s.GEngine)
if UEngine.GEngine then
local n=getNameFromAddress(UEngine.GEngine,true,false,false)
if n:find(extractFileNameWithoutExt(process)) then
registerSymbol('GEngine',getNameFromAddress(UEngine.GEngine), true)
end
end
--todo: use the function method instead until specifically requested to cache the names
log('Loading string table')
synchronize(function()
UEngine.GUI.miStatus.Caption='Loading string table'
end)
if UEngine.NamePoolData==nil then
--can happen in the old stringpool format
local r,err=FindNamePoolData(t)
if not r then
log('Failed searching for NamePool:'..err)
return nil,'FindNamePoolData failed:'..err
end
end
local originalDebugState=disableLuaDebug() --disabling debug here for performance reasons
local err
r,err=CacheNamePool(t)
restoreLuaDebug(originalDebugState)
if not r then
return nil,'CacheNamePool failed:'..err
end
SetupNamePoolLookupType() --the cache is done. make it available to the user
r=true
else
log('New or incomplete state')
if UEngine.NamePoolData==nil then
local sNamePoolData=s.NamePoolData
if sNamePoolData then
UEngine.NamePoolData=getAddressSafe(sNamePoolData)
log('NamePoolData was previously at '..sNamePoolData..' . Using that')
end
end
if UEngine.NamePoolData==nil then
log('Searching for NamePool')
local r,err=FindNamePoolData(t)
if not r then
log('Failed searching for NamePool:'..err)
return nil,'FindNamePoolData failed:'..err
end
local n=getNameFromAddress(UEngine.NamePoolData,true,false,false)
if n:find(extractFileNameWithoutExt(process)) then
--it's a module address. Save it
s.NamePoolData=getNameFromAddress(UEngine.NamePoolData)
end
end
if t and t.Terminated then return nil,'UEInfoScanner terminated' end
--still here, notify that there is some unreal info available
createUEMenu()
if UEngine.NameToIndex == nil then
log('Loading string table')
synchronize(function()
UEngine.GUI.miStatus.Caption='Loading string table'
end)
local originalDebugState=disableLuaDebug() --disabling debug here for performance reasons
local r,err=CacheNamePool(t)
restoreLuaDebug(originalDebugState)
if not r then
return nil,'CacheNamePool failed:'..err
end
SetupNamePoolLookupType() --the cache is done. make it available to the user
end
if t and t.Terminated then return nil,'UEInfoScanner terminated' end
if UEngine.ObjectArray==nil then
local sObjectArray=s.ObjectArray
if sObjectArray then
UEngine.ObjectArray=getAddressSafe(sObjectArray)
end
end
if (UEngine.ObjectArray == nil) or (UEngine.UObject==nil) then
log('Scanning for object table')
synchronize(function()
UEngine.GUI.miStatus.Caption='Scanning for object table'
end)
local r,err=FindObjectArray(t)
if not r then
return nil,'FindObjectArray failed:'..err
end
s.ObjectArray=getNameFromAddress(UEngine.ObjectArray, true, false,false)
end
if UEngine.UGameEngine==nil then
log('Searching for GEngine')
synchronize(function()
UEngine.GUI.miStatus.Caption='Searching for GEngine'
end)
local r,err=FindGEngine(t)
log('FindGEngine returned')
if not r then
if err then
log('FindGEngine failed:'..err)
else
log('FindGEngine failed')
end
return nil,'FindGEngine failed:'..err
end
s.GEngine=getNameFromAddress(UEngine.GEngine,true,false,false)
end
if UEngine.UObject.Class==nil then --normal situation
log('Figuring out the "class" offset')
for i=1,32 do --skip 0 as it's the vftable
local n=UObject_getName(readPointer(UGameEngine+i*4))
if n and n=='GameEngine' then
UEngine.UObject.Class=i*4
break
end
end
end
if UEngine.UObject.Class==nil then
log('Failed finding the "class" offset')
return nil,'UObject.Class not found'
end
UEngine.GameEngineClass=readPointer(UEngine.UGameEngine+UEngine.UObject.Class)
UEngine.UStruct={}
UEngine.UStruct.Name=UEngine.UObject.Name
UEngine.UStruct.Class=UEngine.UObject.Class
--gather more info in case it was missed earlier (some paths don't need it yet)
--the superstruct (UStruct) name of the GameEngine class is Engine
--so find a pointer inside the class that leads to an UObject with the name Engine
--if the game uses an inherited class onject, like OakEngine, then first comes GameEngine (or whatever comes first)
--the superlist will end with Engine->Object
if UEngine.UClass==nil then
UEngine.UClass={}
UEngine.UClass.Name=UEngine.UObject.Name
UEngine.UClass.Class=UEngine.UObject.Class
end
if UEngine.UClass.SuperStruct then --already obtained earlier
UEngine.UStruct.SuperStruct=UEngine.UClass.SuperStruct
else
--superstruct not yet found
if UObject_getName(UEngine.GameEngineClass)=='GameEngine' then
for i=0,32 do
local n=UObject_getName(readPointer(UEngine.GameEngineClass+i*8))
if n and n=='Engine' then --the super of Gameengbine is Engine
UEngine.UStruct.SuperStruct=i*8
break
end
end
else
--it's not a GameEngine class so not sure that comes after (could be more inheritance)
for i=1,32 do
local r=testIfSuperStructOffset(UEngine.GameEngineClass, i*8)
if r and #r>2 then
for j=1,#r do
if r[j]=='Engine' then
UEngine.UStruct.SuperStruct=i*8
break
end
end
if UEngine.UStruct.SuperStruct then
break
end
end
end
end
end
if UEngine.UStruct.SuperStruct==nil then
return nil,'Failed finding the SuperStruct field'
end
UEngine.UClass.Name=UEngine.UStruct.Name
UEngine.UClass.Class=UEngine.UStruct.Class
UEngine.UClass.SuperStruct=UEngine.UStruct.SuperStruct
UEngine.RealGameEngineClass=UEngine.GameEngineClass
--UEngine.GameEngineClass might not be the base "GameEngine" class. Find it if that's the case (to make some assumptions come true)
local c=UEngine.GameEngineClass
while UObject_getName(c)~='GameEngine' do
c=readPointer(c+UEngine.UClass.SuperStruct)
if c==nil then
return nil,'Failure retrieving base GameEngine class'
end
end
UEngine.GameEngineClass=c
if t and t.Terminated then
return nil,'UEInfoScannerThread terminated'
end
--everything ok so far. Try to find the layout of Property Field objects. Can be either UProperty or FProperty. Doesn't matter
log('Figuring out the other offsets (findGameInstanceFPropertyAndFields) ')
synchronize(function()
UEngine.GUI.miStatus.Caption='Figuring out offsets'
end)
r=findGameInstanceFPropertyAndFields(t)
end
if r then
if s.fullyParsed==nil then
--save all offsets
function saveLuaTable(tablename,t)
if t then
for name,value in pairs(t) do
local n=tablename..'.'..name
if type(value)=='table' then
saveLuaTable(n,value)
else
s[n]=tostring(value)
end
end
end
end
saveLuaTable('UEngine.FNameEntry', UEngine.FNameEntry)
saveLuaTable('UEngine.UObject', UEngine.UObject)
saveLuaTable('UEngine.UStruct', UEngine.UStruct)
saveLuaTable('UEngine.UClass', UEngine.UClass)
saveLuaTable('UEngine.FProperty', UEngine.FProperty)
saveLuaTable('UEngine.FFieldClass', UEngine.FFieldClass)
saveLuaTable('UEngine.FField', UEngine.FField)
s['UEngine.VFTableInExecutableMemoryMethod']=UEngine.VFTableInExecutableMemoryMethod
s['UEngine.ObjectArrayListType']=UEngine.ObjectArrayListType
s['UEngine.ObjectArrayEntryStructSize']=UEngine.ObjectArrayEntryStructSize
s['UEngine.NamePoolData_old']=UEngine.NamePoolData_old --nil if not set
s.fullyParsed=true
end
log('success. Registering structure lookup callback')
if registerUEngineStructureLookupCallbacks then --added by UEInfoStructureDissect
synchronize(function()
registerUEngineStructureLookupCallbacks()
--It can be annoying, so add an option to disable it for now
UEngine.GUI.miStructureDissectCallbackStatus=createMenuItem(MainForm)
UEngine.GUI.miStructureDissectCallbackStatus.Caption='Use when dissecting structures'
UEngine.GUI.miStructureDissectCallbackStatus.Name='miStructureDissectCallbackStatus'
UEngine.GUI.miStructureDissectCallbackStatus.AutoCheck=true
UEngine.GUI.miStructureDissectCallbackStatus.Checked=true
UEngine.GUI.miStructureDissectCallbackStatus.OnClick=function()
if UEngine.GUI.miStructureDissectCallbackStatus.checked then
registerUEngineStructureLookupCallbacks()
else
unregisterUEngineStructureLookupCallbacks()
end
end
UEngine.GUI.miUnrealEngine.add(UEngine.GUI.miStructureDissectCallbackStatus)
UEngine.GUI.miStatus.destroy()
UEngine.GUI.miStatus=nil
if UEngine.GUI.miHurry then
UEngine.GUI.miHurry.destroy()
UEngine.GUI.miHurry=nil
end
UEngine.GUI.miUnrealEngine.Caption='Unreal Engine'
end)
end
return r
end
end
function couldBeUnrealEngine()
local pname=extractFileNameWithoutExt(process)
if getAddressSafe(pname..'.agsInit') then return true end
if getAddressSafe(pname..'.agsInitialize') then return true end
--if getAddressSafe(pname..'.NvOptimusEnablement') then return true end --nope (kindergharten has this one as well)
if pname:lower():endsWith('shipping') then return true end
local r=enumModules()
if r then
local v,res=getFileVersion(r[1].PathToFile)
if res then
if res.ProductVersion and res.ProductVersion:find('%+UE4') then return true end
if res.ProductVersion and res.ProductVersion:find('%+UE5') then return true end
end
end
return false
end
function WaitForUnrealEngineInfo(timeout)
if UEInfoScannerThread then
UEInfoScannerThread.Priority='tpHigher'
return UEInfoScannerThread.waitForThread(timeout)
end
return true
end
function LaunchUEInfoScanner()
if UEInfoScannerThread then
UEInfoScannerThread.Terminate()
if UEInfoScannerThread.waitFor(5000) then
UEInfoScannerThread.destroy() UEInfoScannerThread=nil
end
UEInfoScannerThread=nil
end
UEInfoScannerThread=createThread(function(t)
log('UEInfoScannerThread started')
t.Priority='tpIdle'
local r,err=UEInfoScanner(t)
log('UEInfoScannerThread finished')
if r then
log('UEInfoScanner: Success')
synchronize(function()
UEngine.GUI.miUnrealEngine.caption='Unreal Engine'
end)
else
if err then
log('UEInfoScanner failure:'..err)
else
log('UEInfoScanner failure')
end
synchronize(function()
if UEngine.GUI and UEngine.GUI.miUnrealEngine then
UEngine.GUI.miUnrealEngine.destroy()
UEngine.GUI=nil
end
end)
end
--if err then
-- print(err)
--end
end)
end
local oldOnProcessOpened=MainForm.OnProcessOpened
MainForm.OnProcessOpened=function()
if UEInfoScannerThread then
UEInfoScannerThread.Terminate()
end
if couldBeUnrealEngine() then
LaunchUEInfoScanner()
end
local r=oldOnProcessOpened()
end
|