Skip to content

Commit

Permalink
Merge pull request #1 from skiff/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
skiff committed Jun 30, 2021
2 parents abfc62e + 7b0a608 commit a79ee31
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 7 deletions.
10 changes: 8 additions & 2 deletions libpsutil/encryption/rc4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,14 @@ namespace libpsutil
for (int i = 0; i < N; i++)
S[i] = i;

for (int i = 0; i < N; i++) {
for (int i = 0; i < N; i++)
{
j = (j + S[i] + key[i % len]) % N;

swap(&S[i], &S[j]);
}

return 0;
}

int PRGA(unsigned char* S, char* plaintext, unsigned char* ciphertext)
Expand All @@ -48,8 +51,9 @@ namespace libpsutil
int rnd = S[(S[i] + S[j]) % N];

ciphertext[n] = rnd ^ plaintext[n];

}

return 0;
}
}

Expand All @@ -59,6 +63,8 @@ namespace libpsutil
KSA(key, S);

PRGA(S, plaintext, ciphertext);

return 0;
}
}
}
12 changes: 11 additions & 1 deletion libpsutil/libpsutil.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,24 @@
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|PS3'" />
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|PS3'">
<ClCompile>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions);</PreprocessorDefinitions>
<OptimizationLevel>Level2</OptimizationLevel>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<CppLanguageStd>Cpp11</CppLanguageStd>
</ClCompile>
<CustomBuildStep>
<Command>
</Command>
</CustomBuildStep>
<PostBuildEvent>
<Command>copy /y "$(TargetPath)" "$(SCE_PS3_ROOT)/target/ppu/lib/"</Command>
</PostBuildEvent>
<PostBuildEvent>
<Message>Copy Lib to SCE Lib Directory</Message>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="encryption\rc4.cpp" />
Expand Down
24 changes: 20 additions & 4 deletions libpsutil/system/memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ namespace libpsutil

bool nop(uint32_t address)
{
return set<uint32_t>(address, 0x60000000) == SUCCEEDED;
return memory::set<uint32_t>(address, 0x60000000);
}

bool blr(uint32_t address)
{
return set<uint32_t>(address, 0x4E800020) == SUCCEEDED;
return memory::set<uint32_t>(address, 0x4E800020);
}

void jump(uint32_t address, uint32_t destination, bool linked)
Expand All @@ -51,6 +51,22 @@ namespace libpsutil
memory::set(address, instructions, sizeof(uint32_t) * 4);
}

void jump_safe(uint32_t address, uint32_t destination, bool linked)
{
uint32_t instructions[8] = { 0 };

instructions[0] = 0xF821FFF9;
instructions[1] = 0xF8010000;
instructions[2] = 0x3C000000 + ((destination >> 16) & 0xFFFF);
instructions[3] = 0x60000000 + (destination & 0xFFFF);
instructions[4] = 0x7C0903A6;
instructions[5] = 0xE8010000;
instructions[6] = 0x38210008;
instructions[7] = 0x4E800420 + (linked ? 1 : 0);

memory::set(address, instructions, sizeof(uint32_t) * 8);
}

uint32_t get_game_toc()
{
uint32_t* entry_point = *reinterpret_cast<uint32_t**>(0x1001C); //ElfHeader->e_entry
Expand All @@ -65,7 +81,7 @@ namespace libpsutil
stub_section = reinterpret_cast<uint8_t*>(detour::force_stub_addr);
}

auto stub_address = reinterpret_cast<uint32_t>(&stub_section[this->hook_count * 0x80]);
auto stub_address = reinterpret_cast<uint32_t>(&stub_section[this->hook_count * 0x90]);
this->hook_count++;

return stub_address;
Expand Down Expand Up @@ -111,7 +127,7 @@ namespace libpsutil
}
}

memory::jump(reinterpret_cast<uint32_t>(&stub_address[instruction_count]), address + 0x10, false);
memory::jump_safe(reinterpret_cast<uint32_t>(&stub_address[instruction_count]), address + 0x10, false);
memory::jump(address, *reinterpret_cast<uint32_t*>(destination), false);

this->stub_opd[0] = reinterpret_cast<uint32_t>(stub_address);
Expand Down
1 change: 1 addition & 0 deletions libpsutil/system/memory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ namespace libpsutil
bool blr(uint32_t address);

void jump(uint32_t address, uint32_t destination, bool linked = false);
void jump_safe(uint32_t address, uint32_t destination, bool linked = false);

uint32_t get_game_toc();

Expand Down

0 comments on commit a79ee31

Please sign in to comment.