Current section
Files
Jump to
Current section
Files
src/gpkm@sav@decrypt.erl
-module(gpkm@sav@decrypt).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([decrypt_pkm/1]).
-file("src/gpkm/sav/decrypt.gleam", 7).
-spec tr_unencrypt_chunks(list(list(integer())), integer(), list(integer())) -> list(integer()).
tr_unencrypt_chunks(Bytes_chunks, Rand_value, Res) ->
case Bytes_chunks of
[] ->
_pipe = Res,
lists:reverse(_pipe);
[Chunk | T] ->
Next_rand = gpkm@sav@blocks:rand(Rand_value),
Rand_i16 = gpkm@utils@bytes:take_upper_16_bits(Rand_value),
Chunk_i16 = gpkm@utils@bytes:to_int(Chunk),
Unencrypted_byte = erlang:'bxor'(Chunk_i16, Rand_i16),
tr_unencrypt_chunks(T, Next_rand, [Unencrypted_byte | Res])
end.
-file("src/gpkm/sav/decrypt.gleam", 25).
-spec unencrypt_chunks_as_bytes(list(list(integer())), list(integer())) -> list(integer()).
unencrypt_chunks_as_bytes(Bytes_chunks, Rand_seed) ->
Initial_rand_value = begin
_pipe = Rand_seed,
_pipe@1 = gpkm@utils@bytes:to_int(_pipe),
gpkm@sav@blocks:rand(_pipe@1)
end,
_pipe@2 = tr_unencrypt_chunks(Bytes_chunks, Initial_rand_value, []),
gleam@list:flat_map(
_pipe@2,
fun(_capture) ->
gpkm@utils@bytes:i16_to_i8_bytes(_capture, little_endian)
end
).
-file("src/gpkm/sav/decrypt.gleam", 32).
-spec decrypt_pkm(bitstring()) -> list(integer()).
decrypt_pkm(Pkm_bits) ->
Pkm_bytes = erlang:binary_to_list(Pkm_bits),
Header = gpkm@pkm@ser_de:get_unencrypted_header(Pkm_bytes, little_endian),
Decrypted_block_bytes = begin
_pipe = Pkm_bytes,
_pipe@1 = gpkm@utils@bytes:chunked_slice(
_pipe,
16#08,
16#87,
2,
little_endian
),
_pipe@2 = unencrypt_chunks_as_bytes(_pipe@1, erlang:element(4, Header)),
gpkm@sav@blocks:shuffle_block_bytes(
_pipe@2,
erlang:element(2, Header),
decrypt
)
end,
Decrypted_non_block_bytes = begin
_pipe@3 = Pkm_bytes,
_pipe@4 = gpkm@utils@bytes:chunked_slice(
_pipe@3,
16#88,
16#eb,
2,
little_endian
),
unencrypt_chunks_as_bytes(_pipe@4, erlang:element(2, Header))
end,
Decrypted_pkm = begin
_pipe@5 = Header,
_pipe@6 = gpkm@pkm@ser_de:header_as_bytes(_pipe@5),
_pipe@7 = lists:append(_pipe@6, Decrypted_block_bytes),
lists:append(_pipe@7, Decrypted_non_block_bytes)
end,
Decrypted_pkm.