<commit_before>/*
 * Copyright (c) Meta Platforms, Inc. and affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */

#pragma once

#include <cstdlib>
#include <cstring>
#include <functional>
#include <initializer_list>
#include <limits>
#include <memory>
#include <optional>
#include <string>
#include <utility>

#include "Debug.h"
#include "DexAccess.h"
#include "DexAnnotation.h"
#include "DexDefs.h"
#include "DexEncoding.h"
#include "RedexContext.h"
#include "ReferencedState.h"
#include "Util.h"

/*
 * The structures defined here are literal representations
 * of what can be represented in a dex.  The main purpose of
 * the translations present here are to decouple the limitations
 * of "Idx" representation.  All of the "Idx"'s are indexes into
 * arrays of types in the dex format.  They are specific to each
 * dexfile.  So, we transform them in a way that we can load
 * multiple dexes in memory and compare them symbolically.
 *
 * In doing so, we enforce the uniqueness requirements of Idx's
 * within dexes.  There's only one DexString* with the same
 * set of characters.  Only one DexType* that has name "Foo;".
 * That simplifies the process of re-marshalling to dex after
 * we've completed whatever transforms we are going to do.
 *
 * UNIQUENESS:
 * The private constructor pattern enforces the uniqueness of
 * the pointer values of each type that has a uniqueness requirement.
 *
 *
 *
 * Gather methods:
 * Most `gather_X` methods are templated over the container type.
 * Currently only `std::vector` and `std::unordered_set` are supported.
 * The definitions are not in the header so as to avoid overly broad
 * imports.
 */

class DexClass;
class DexDebugInstruction;
class DexField;
class DexIdx;
class DexInstruction;
class DexOutputIdx;
struct DexPosition;
class DexString;
class DexType;
class PositionMapper;

constexpr bool kInsertDeobfuscatedNameLinks = true;

using Scope = std::vector<DexClass*>;

#if defined(__SSE4_2__) && defined(__linux__) && defined(__STRCMP_LESS__)
extern "C" bool strcmp_less(const char* str1, const char* str2);
#endif

class DexString {
  friend struct RedexContext;

  std::string m_storage;
  uint32_t m_utfsize;

  // See UNIQUENESS above for the rationale for the private constructor pattern.
  explicit DexString(std::string nstr)
      : m_storage(std::move(nstr)),<commit_msg>Toggle deobfuscated link flag<commit_after>/*
 * Copyright (c) Meta Platforms, Inc. and affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */

#pragma once

#include <cstdlib>
#include <cstring>
#include <functional>
#include <initializer_list>
#include <limits>
#include <memory>
#include <optional>
#include <string>
#include <utility>

#include "Debug.h"
#include "DexAccess.h"
#include "DexAnnotation.h"
#include "DexDefs.h"
#include "DexEncoding.h"
#include "RedexContext.h"
#include "ReferencedState.h"
#include "Util.h"

/*
 * The structures defined here are literal representations
 * of what can be represented in a dex.  The main purpose of
 * the translations present here are to decouple the limitations
 * of "Idx" representation.  All of the "Idx"'s are indexes into
 * arrays of types in the dex format.  They are specific to each
 * dexfile.  So, we transform them in a way that we can load
 * multiple dexes in memory and compare them symbolically.
 *
 * In doing so, we enforce the uniqueness requirements of Idx's
 * within dexes.  There's only one DexString* with the same
 * set of characters.  Only one DexType* that has name "Foo;".
 * That simplifies the process of re-marshalling to dex after
 * we've completed whatever transforms we are going to do.
 *
 * UNIQUENESS:
 * The private constructor pattern enforces the uniqueness of
 * the pointer values of each type that has a uniqueness requirement.
 *
 *
 *
 * Gather methods:
 * Most `gather_X` methods are templated over the container type.
 * Currently only `std::vector` and `std::unordered_set` are supported.
 * The definitions are not in the header so as to avoid overly broad
 * imports.
 */

class DexClass;
class DexDebugInstruction;
class DexField;
class DexIdx;
class DexInstruction;
class DexOutputIdx;
struct DexPosition;
class DexString;
class DexType;
class PositionMapper;

constexpr bool kInsertDeobfuscatedNameLinks = false;

using Scope = std::vector<DexClass*>;

#if defined(__SSE4_2__) && defined(__linux__) && defined(__STRCMP_LESS__)
extern "C" bool strcmp_less(const char* str1, const char* str2);
#endif

class DexString {
  friend struct RedexContext;

  std::string m_storage;
  uint32_t m_utfsize;

  // See UNIQUENESS above for the rationale for the private constructor pattern.
  explicit DexString(std::string nstr)
      : m_storage(std::move(nstr)),
{'fraction_non_alphanumeric': 0.0847145488029466, 'fraction_numerical': 0.0024554941682013503, 'mean_word_length': 4.605504587155964, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '875612', 'n_tokens_mistral': 1514, 'n_tokens_neox': 1437, 'n_words': 602}