class_docstr: Implementation of the following white-box attacks related to PE malware crafting:
      1) Append based attacks (example paper link: https://arxiv.org/abs/1810.08280)
      2) Section insertion attacks (example paper link: https://arxiv.org/abs/2008.07125)
      3) Slack manipulation attacks (example paper link: https://arxiv.org/abs/1810.08280)
      4) DOS Header Attacks (example paper link: https://arxiv.org/abs/1901.03583)
class_docstr_tok: ["Implementation","of","the","following","white-box","attacks","related","to","PE","malware","crafting",":","1",")","Append","based","attacks","(","example","paper","link",":","https",":","\/\/arxiv.org\/abs\/1810.08280",")","2",")","Section","insertion","attacks","(","example","paper","link",":","https",":","\/\/arxiv.org\/abs\/2008.07125",")","3",")","Slack","manipulation","attacks","(","example","paper","link",":","https",":","\/\/arxiv.org\/abs\/1810.08280",")","4",")","DOS","Header","Attacks","(","example","paper","link",":","https",":","\/\/arxiv.org\/abs\/1901.03583",")"]
docstr: Project the adversarial example back though the closest l2 vector.
  
  :embeddings: Adversarially optimised embeddings
  :labels: Labels for the data
  :fsize: Size of the original malware
  :data: Original data in the feature space
  :perturbation_size: Size of the l0 attack to append (if any).
  :perturb_sizes: List, with each element itself being a list of the start positions of a
                  perturbation regions in a sample
  :perturb_starts: List, with each element itself being a list of the start positions of a
                   start of the perturbation regions in a sample
  
  :return data: Numpy array with valid data samples.
docstr_tok: ["Project","the","adversarial","example","back","though","the","closest","l2","vector",".",":","embeddings",":","Adversarially","optimised","embeddings",":","labels",":","Labels","for","the","data",":","fsize",":","Size","of","the","original","malware",":","data",":","Original","data","in","the","feature","space",":","perturbation_size",":","Size","of","the","l0","attack","to","append","(","if","any",")",".",":","perturb_sizes",":","List",",","with","each","element","itself","being","a","list","of","the","start","positions","of","a","perturbation","regions","in","a","sample",":","perturb_starts",":","List",",","with","each","element","itself","being","a","list","of","the","start","positions","of","a","start","of","the","perturbation","regions","in","a","sample",":","return","data",":","Numpy","array","with","valid","data","samples","."]
code: def get_adv_malware(
      self,
      embeddings: "tf.Tensor",
      data: np.ndarray,
      labels: np.ndarray,
      fsize: np.ndarray,
      perturbation_size: np.ndarray,
      perturb_sizes: Optional[List[List[int]]] = None,
      perturb_starts: Optional[List[List[int]]] = None,
  ) -> np.ndarray:
      """
      Project the adversarial example back though the closest l2 vector.
  
      :embeddings: Adversarially optimised embeddings
      :labels: Labels for the data
      :fsize: Size of the original malware
      :data: Original data in the feature space
      :perturbation_size: Size of the l0 attack to append (if any).
      :perturb_sizes: List, with each element itself being a list of the start positions of a
                      perturbation regions in a sample
      :perturb_starts: List, with each element itself being a list of the start positions of a
                       start of the perturbation regions in a sample
  
      :return data: Numpy array with valid data samples.
      """
      import tensorflow as tf
  
      for i, label in enumerate(labels):
          if label == 1:
              total_diff = 0
              m = tf.constant(
                  [1, self.param_dic["input_dim"], 1], tf.int32
              )
  
              if (
                  perturb_sizes is not None
                  and perturb_starts is not None
              ):
                  for size, start in zip(
                      perturb_sizes[i], perturb_starts[i]
                  ):
                      expanded = tf.tile(
                          tf.expand_dims(
                              embeddings[i, start : start + size, :],
                              axis=1,
                          ),
                          m,
                      )
                      diff = tf.norm(
                          (expanded - self.embedding_weights), axis=-1
                      )
                      diff = tf.math.argmin(diff, axis=-1)
                      data[i, start : start + size] = diff
                      total_diff += len(diff)
              expanded = tf.tile(
                  tf.expand_dims(
                      embeddings[
                          i,
                          fsize[i] : fsize[i] + perturbation_size[i],
                          :,
                      ],
                      axis=1,
                  ),
                  m,
              )
              diff = tf.norm(
                  (expanded - self.embedding_weights), axis=-1
              )
              diff = tf.math.argmin(diff, axis=-1)
              data[i, fsize[i] : fsize[i] + perturbation_size[i]] = diff
              total_diff += len(diff)
  
              # sanity check that the total number of perturbed features does
              # not exceed the total perturbation budget
              assert total_diff == self.total_perturbation[i]
      return data
  
imports: import json
  import random
  import logging
  from typing import Optional, Union, Tuple, List, Dict, TYPE_CHECKING
  from tqdm.auto import trange
  import numpy
  from art.estimators.estimator import BaseEstimator, NeuralNetworkMixin
  from art.estimators.classification.classifier import ClassifierMixin
  from art.attacks.attack import EvasionAttack
label_desc: Use image node_id 7 for calling the MalwareGDTensorFlow obj's underlying member method code with example usage: obj.get_adv_malware(embeddings, data, labels, fsize, perturbation_size, perturb_sizes, perturb_starts) and returns: data