Skip to content
This repository has been archived by the owner on Sep 27, 2022. It is now read-only.

Commit

Permalink
decrypt settings as json
Browse files Browse the repository at this point in the history
  • Loading branch information
atilaromero committed Mar 20, 2019
1 parent 9f3d044 commit ed1f7eb
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
17 changes: 15 additions & 2 deletions cmd/telegram-desktop-decrypt/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,24 @@ func main() {
log.Fatalf("could not interpret settings file: %+v", err)
}
settingsKey := settings.GetKey(password)
decrypted, err := settings.Decrypt(settingsKey)
os.Stdout.Write(decrypted)
plain, err := settings.Decrypt(settingsKey)
if !parse {
os.Stdout.Write(plain)
return
}
parsed, err := decrypted.ParseCache(plain, decrypted.ReverseLSK(decrypted.UserSettings{}))
if err != nil {
log.Fatalf("could not interpret settings file: %+v", err)
}
m, err := json.Marshal(parsed)
if err != nil {
log.Fatalf("could not interpret settings file: %+v", err)
}
os.Stdout.Write(m)
},
}
cmdSettingsDecrypt.Flags().StringVarP(&password, "password", "p", "", "optional password (default='')")
cmdSettingsDecrypt.Flags().BoolVarP(&parse, "parse", "", true, "(default=true)")
cmdSettings.AddCommand(cmdSettingsDecrypt)

cmdMap := &cobra.Command{
Expand Down
20 changes: 20 additions & 0 deletions tdata/decrypted/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,23 @@ func ExampleParseCache_b() {
// Output:
// {"FullLen":174,"Locations":[{"MediaKey":{"LocationType":"DocumentFileLocation","DC":1,"ID":"0x4481d5870000003d"},"LegacyType":0,"Filename":"/home/atila.alr/Pictures/Spotify.png","Bookmark":"","DateTime":"2016-09-12T10:11:47.262Z","Size":172940}]}
}

func ExampleParseCache_c() {
data, err := hex.DecodeString("3203000000000003000000c80000003200030d4000000035000000c800000043000000c80000005000000005000000060000000000000007000000000000001d0000000000000009000000000000000a000000000000000c000000010000000d0000000000000016000000000000004a0000025cffffffff0000000d0000000100000000000001bb0000000e3134392e3135342e3137352e3530000000000000000100000001000001bb00000027323030313a306232383a663233643a663030313a303030303a303030303a303030303a30303061000000000000000200000000000001bb0000000e3134392e3135342e3136372e3531000000000000000200000001000001bb00000027323030313a303637633a303465383a663030323a303030303a303030303a303030303a30303061000000000000000300000000000001bb0000000f3134392e3135342e3137352e313030000000000000000300000001000001bb00000027323030313a306232383a663233643a663030333a303030303a303030303a303030303a30303061000000000000000400000000000001bb0000000e3134392e3135342e3136372e3931000000000000000400000001000001bb00000027323030313a303637633a303465383a663030343a303030303a303030303a303030303a30303061000000000000000400000002000001bb0000000f3134392e3135342e3136342e323530000000000000000400000003000001bb00000027323030313a303637633a303465383a663030343a303030303a303030303a303030303a30303062000000000000000500000001000001bb00000027323030313a306232383a663233663a663030353a303030303a303030303a303030303a30303061000000000000000500000010000001bb0000000d39312e3130382e35362e323030000000000000000500000000000001bb0000000d39312e3130382e35362e3137350000000000000000000000190000001a00350035003500310039003900390037003700390030003700300000004f0000000400000000ffffffff00000028000000010000004ea642b24495ee2a550000000e0000000200000018000004ac0000073ac674053f0000000049fad6985298f9b321101418ed78")

if err != nil {
fmt.Println(err)
}

cache, err := ParseCache(data, ReverseLSK(UserSettings{}))
if err != nil {
fmt.Println(err)
}
b, err := json.Marshal(cache)
if err != nil {
fmt.Println(err)
}
fmt.Println(string(b))
// Output:
// {"FullLen":818,"DbiDcOptionOldOld":{"DcId":0,"Host":"","IP":"","Port":0},"DbiDcOptionOld":{"DcIdWithShift":0,"Flags":0,"IP":"","Port":0},"DbiDcOptions":{"Serialized":"/////wAAAA0AAAABAAAAAAAAAbsAAAAOMTQ5LjE1NC4xNzUuNTAAAAAAAAAAAQAAAAEAAAG7AAAAJzIwMDE6MGIyODpmMjNkOmYwMDE6MDAwMDowMDAwOjAwMDA6MDAwYQAAAAAAAAACAAAAAAAAAbsAAAAOMTQ5LjE1NC4xNjcuNTEAAAAAAAAAAgAAAAEAAAG7AAAAJzIwMDE6MDY3YzowNGU4OmYwMDI6MDAwMDowMDAwOjAwMDA6MDAwYQAAAAAAAAADAAAAAAAAAbsAAAAPMTQ5LjE1NC4xNzUuMTAwAAAAAAAAAAMAAAABAAABuwAAACcyMDAxOjBiMjg6ZjIzZDpmMDAzOjAwMDA6MDAwMDowMDAwOjAwMGEAAAAAAAAABAAAAAAAAAG7AAAADjE0OS4xNTQuMTY3LjkxAAAAAAAAAAQAAAABAAABuwAAACcyMDAxOjA2N2M6MDRlODpmMDA0OjAwMDA6MDAwMDowMDAwOjAwMGEAAAAAAAAABAAAAAIAAAG7AAAADzE0OS4xNTQuMTY0LjI1MAAAAAAAAAAEAAAAAwAAAbsAAAAnMjAwMTowNjdjOjA0ZTg6ZjAwNDowMDAwOjAwMDA6MDAwMDowMDBiAAAAAAAAAAUAAAABAAABuwAAACcyMDAxOjBiMjg6ZjIzZjpmMDA1OjAwMDA6MDAwMDowMDAwOjAwMGEAAAAAAAAABQAAABAAAAG7AAAADTkxLjEwOC41Ni4yMDAAAAAAAAAABQAAAAAAAAG7AAAADTkxLjEwOC41Ni4xNzUAAAAAAAAAAA=="},"DbiChatSizeMax":200,"DbiSavedGifsLimit":200,"DbiStickersRecentLimit":200,"DbiStickersFavedLimit":5,"DbiMegagroupSizeMax":200000,"DbiUser":{"UserId":0,"DcId":0},"DbiKey":{"DcId":-1,"Key":"AAAAAQAAAE6mQrJEle4qVQAAAA4AAAACAAAAGAAABKwAAAc6xnQFPw=="},"DbiMtpAuthorization":{"Serialized":null},"DbiAutoStart":0,"DbiStartMinimized":0,"DbiSendToMenu":0,"DbiUseExternalVideoPlayer":0,"DbiCacheSettings":{"Size":0,"Time":0},"DbiAnimationsDisabled":0,"DbiSoundNotify":0,"DbiAutoDownload":{"Photo":0,"Audio":0,"Gif":0},"DbiAutoPlay":0,"DbiDialogsMode":{"Enabled":0,"ModeInt":0},"DbiModerateMode":0,"DbiIncludeMutedOld":0,"DbiShowingSavedGifsOld":0,"DbiDesktopNotify":0,"DbiWindowsNotificationsOld":0,"DbiNativeNotifications":0,"DbiNotificationsCount":0,"DbiNotificationsCorner":0,"DbiDialogsWidthRatioOld":0,"DbiLastSeenWarningSeenOld":0,"DbiAuthSessionSettings":{"V":null},"DbiWorkMode":0,"DbiTxtDomainString":"","DbiConnectionTypeOld":{"V":0,"Host":"","Port":0,"User":"","Password":""},"DbiConnectionType":4,"DbiThemeKeyOld":0,"DbiThemeKey":{"KeyDay":0,"KeyNight":0,"NightMode":0},"DbiLangPackKey":0,"DbiLanguagesKey":0,"DbiTryIPv6":0,"DbiSeenTrayTooltip":0,"DbiAutoUpdate":1,"DbiLastUpdateCheck":0,"DbiScaleOld":0,"DbiScalePercent":0,"DbiLangOld":0,"DbiLangFileOld":"","DbiWindowPosition":{"X":0,"Y":0,"W":0,"H":0,"Moncrc":0,"Maximized":0},"DbiLoggedPhoneNumber":"5551999779070","DbiMutePeer":0,"DbiMutedPeers":{"Count":0,"Peers":null},"DbiSendKeyOld":0,"DbiCatsAndDogs":0,"DbiTileBackgroundOld":0,"DbiTileBackground":{"TileDay":0,"TileNight":0},"DbiAdaptiveForWide":0,"DbiAutoLock":0,"DbiReplaceEmoji":0,"DbiSuggestEmoji":0,"DbiSuggestStickersByEmoji":0,"DbiDefaultAttach":0,"DbiNotifyView":0,"DbiAskDownloadPath":0,"DbiDownloadPathOld":"","DbiDownloadPath":{"V":"","Bookmark":null},"DbiCompressPastedImage":0,"DbiEmojiTabOld":0,"DbiRecentEmojiOldOld":null,"DbiRecentEmojiOld":null,"DbiRecentEmoji":null,"DbiRecentStickers":null,"DbiEmojiVariantsOld":null,"DbiEmojiVariants":null,"DbiHiddenPinnedMessages":null,"DbiDialogLastPath":"","DbiSongVolume":0,"DbiVideoVolume":0,"DbiPlaybackSpeed":0}
}

0 comments on commit ed1f7eb

Please sign in to comment.