Ejemplo n.º 1
0
void ExifShellExtension::PasteExifFromClipboard()
{
   Win32::Clipboard cb(GetActiveWindow());

   if (cb.IsFormatAvail(m_uiExifClipboardFormat))
   {
      std::vector<BYTE> vecData;
      cb.GetData(m_uiExifClipboardFormat, vecData);

      CString cszOutputFilename = m_cszFilename + _T(".exifshellext-rename");

      // rewrite jpeg file using new exif data
      {
         Stream::FileStream streamIn(m_cszFilename, Stream::FileStream::modeOpen, Stream::FileStream::accessRead,
            Stream::FileStream::shareRead);

         Stream::FileStream streamOut(cszOutputFilename, Stream::FileStream::modeCreateNew, Stream::FileStream::accessWrite,
            Stream::FileStream::shareRead);

         ExifRewriter rewriter(streamIn, streamOut, vecData);
         rewriter.Start();
      }

      // TODO now set old file date/time

      // rename
      ::DeleteFile(m_cszFilename);
      ::MoveFile(cszOutputFilename, m_cszFilename);
   }
}
Ejemplo n.º 2
0
int main(int argc, char** argv) {
   /**
    *
    */
   if (argc < 2) {
      fprintf(stdout, "Usage: ./program <binary to rewrite>\n");
      exit(EXIT_SUCCESS);
   }

   BinaryRewriter rewriter(argv[1]);

   return 0;
}
Ejemplo n.º 3
0
std::string
RefactoringTool::transform(CustomToolInvocation& invocation,
                           clang::tooling::FrontendActionFactory *actionFactory)
{
  invocation.run(actionFactory->create());

  //create rewriter
  clang::LangOptions defaultLangOptions;
  clang::Rewriter rewriter(invocation.getSources(), defaultLangOptions);
  if (_replacements.empty()) {
    return invocation.code();
  }
  // apply replacements
  applyAllReplacements(_replacements, rewriter);
  // create replacements
  _replacements.clear();
  // write replacements to buffer
  return writeReplacements(rewriter);
}
void BytecodeGeneratorification::run()
{
    // We calculate the liveness at each merge point. This gives us the information which registers should be saved and resumed conservatively.

    {
        GeneratorLivenessAnalysis pass(*this);
        pass.run(m_codeBlock, m_instructions);
    }

    BytecodeRewriter rewriter(m_bytecodeGenerator, m_graph, m_codeBlock, m_instructions);

    // Setup the global switch for the generator.
    {
        auto nextToEnterPoint = enterPoint().next();
        unsigned switchTableIndex = m_codeBlock->numberOfSwitchJumpTables();
        VirtualRegister state = virtualRegisterForArgument(static_cast<int32_t>(JSGeneratorFunction::GeneratorArgument::State));
        auto& jumpTable = m_codeBlock->addSwitchJumpTable();
        jumpTable.min = 0;
        jumpTable.branchOffsets.resize(m_yields.size() + 1);
        jumpTable.branchOffsets.fill(0);
        jumpTable.add(0, nextToEnterPoint.offset());
        for (unsigned i = 0; i < m_yields.size(); ++i)
            jumpTable.add(i + 1, m_yields[i].point);

        rewriter.insertFragmentBefore(nextToEnterPoint, [&](BytecodeRewriter::Fragment& fragment) {
            fragment.appendInstruction<OpSwitchImm>(switchTableIndex, BoundLabel(nextToEnterPoint.offset()), state);
        });
    }

    for (const YieldData& data : m_yields) {
        VirtualRegister scope = virtualRegisterForArgument(static_cast<int32_t>(JSGeneratorFunction::GeneratorArgument::Frame));

        auto instruction = m_instructions.at(data.point);
        // Emit save sequence.
        rewriter.insertFragmentBefore(instruction, [&](BytecodeRewriter::Fragment& fragment) {
            data.liveness.forEachSetBit([&](size_t index) {
                VirtualRegister operand = virtualRegisterForLocal(index);
                Storage storage = storageForGeneratorLocal(index);

                fragment.appendInstruction<OpPutToScope>(
                    scope, // scope
                    storage.identifierIndex, // identifier
                    operand, // value
                    GetPutInfo(DoNotThrowIfNotFound, LocalClosureVar, InitializationMode::NotInitialization), // info
                    m_generatorFrameSymbolTableIndex, // symbol table constant index
                    storage.scopeOffset.offset() // scope offset
                );
            });

            // Insert op_ret just after save sequence.
            fragment.appendInstruction<OpRet>(data.argument);
        });

        // Emit resume sequence.
        rewriter.insertFragmentAfter(instruction, [&](BytecodeRewriter::Fragment& fragment) {
            data.liveness.forEachSetBit([&](size_t index) {
                VirtualRegister operand = virtualRegisterForLocal(index);
                Storage storage = storageForGeneratorLocal(index);

                fragment.appendInstruction<OpGetFromScope>(
                    operand, // dst
                    scope, // scope
                    storage.identifierIndex, // identifier
                    GetPutInfo(DoNotThrowIfNotFound, LocalClosureVar, InitializationMode::NotInitialization), // info
                    0, // local scope depth
                    storage.scopeOffset.offset() // scope offset
                );
            });
        });

        // Clip the unnecessary bytecodes.
        rewriter.removeBytecode(instruction);
    }

    rewriter.execute();
}