void CheckFormat(unsigned char *buffer, char opt, unsigned char *extraopt, int extraopt2, unsigned char *extraopt3){
	// here we check file format we will begin with PE and ELF
		void *name;
		if(buffer[0] == 0x7f && buffer[1] == 0x45){
			printf("this file is ELF \n");
		}else if(buffer[0] == 0x4d && buffer[1] == 0x5a){
			printf("this file is PE file\n");
			if(opt == 'a')
				PeAnalyzer(buffer, opt);
			else if(opt == 'I')
				DumpImports(buffer, opt);
			else if(opt == 's')
				ListSections(buffer, opt);
			else if(opt == 'n')
				GetSection(buffer, opt, extraopt);
			else if(opt == 'N')
				DumpSecHex(buffer, opt, extraopt);
			else if(opt == 'S')
				DumpStrings(buffer, opt, extraopt);
			else if(opt == 'f')
				DisassembleCap(buffer, opt, extraopt, extraopt2);
			else if(opt == 'c')
				DisassembleCapOffset(buffer, opt, extraopt, extraopt3);
		}
	// free(format);
}
示例#2
0
void DumpFunction(TFunc* tf, FILE* D)
{
 lastF=tf;
 ThreadCode(tf->code,tf->code+tf->size);
 fputc(ID_FUN,D);
 DumpSize(tf->size,D);
 DumpWord(tf->lineDefined,D);
 if (IsMain(tf))
  DumpString(tf->fileName,D);
 else
  DumpWord(tf->marked,D);
 DumpBlock(tf->code,tf->size,D);
 DumpStrings(D);
}
示例#3
0
void DumpPeFile(hadesmem::Process const& process,
                hadesmem::PeFile const& pe_file,
                std::wstring const& path)
{
  std::wostream& out = GetOutputStreamW();

  ClearWarnForCurrentFile();

  WriteNewline(out);
  std::wstring const architecture_str{pe_file.Is64() ? L"64-Bit File: Yes"
                                                     : L"64-Bit File: No"};
  WriteNormal(out, architecture_str, 1);

  std::uint32_t const k1MB = (1U << 20);
  std::uint32_t const k100MB = k1MB * 100;
  if (pe_file.GetSize() > k100MB)
  {
    // Not actually unsupported, just want to flag large files for use in perf
    // testing.
    WriteNewline(out);
    WriteNormal(out, L"WARNING! File is over 100MB.", 0);
    // WarnForCurrentFile(WarningType::kUnsupported);
  }

  DumpHeaders(process, pe_file);

  DumpSections(process, pe_file);

  DumpOverlay(process, pe_file);

  DumpTls(process, pe_file);

  DumpExports(process, pe_file);

  bool has_new_bound_imports_any = false;
  DumpImports(process, pe_file, has_new_bound_imports_any);

  DumpBoundImports(process, pe_file, has_new_bound_imports_any);

  DumpRelocations(process, pe_file);

  if (!g_quiet && g_strings)
  {
    DumpStrings(process, pe_file);
  }

  HandleWarnings(path);
}
int main(int argc, char **argv)
{
	if(argc!=4)
	{
		printf("usage; %s infile outstring outcode\n",argv[0]);
		return 0;
	}
	
	infile = fopen(argv[1],"rb");
	if(!infile)
	{
		printf("Could not open %s\n",argv[1]);
		return -1;
	}
	
	fread(&scrhead,1,sizeof(scrhead),infile);
	
	strings = (Entry*)calloc(scrhead.strindex.size,sizeof(Entry));
	labels = (int*)calloc(scrhead.labels.size+1,sizeof(int));
	markers = (int*)calloc(scrhead.markers.size+1,sizeof(int));
	unk12 = (int*)calloc(scrhead.unk12.size+1,sizeof(int));
	unk13 = (int*)calloc(scrhead.unk13.size+1,sizeof(int));
	
	fseek(infile,scrhead.strindex.offset,SEEK_SET);
	fread(strings,1,scrhead.strindex.size*8,infile);
	
	setlocale(LC_ALL, "Japanese");

	ParseTable(labels,scrhead.labels.offset,scrhead.labels.size);
	ParseTable(markers,scrhead.markers.offset,scrhead.markers.size);
	ParseTable(unk12,scrhead.unk12.offset,scrhead.unk12.size);
	ParseTable(unk13,scrhead.unk13.offset,scrhead.unk13.size);
	
	DumpStrings(argv[2]);
	DumpBytecode(argv[3],argv[1],argv[2]);
	
	fclose(infile);

	return 0;
}
示例#5
0
文件: main.cpp 项目: lvous/hadesmem
void DumpPeFile(hadesmem::Process const& process,
                hadesmem::PeFile const& pe_file,
                std::wstring const& path)
{
  std::wostream& out = std::wcout;

  ClearWarnForCurrentFile();

  std::uint32_t const k1MB = (1U << 20);
  std::uint32_t const k100MB = k1MB * 100;
  if (pe_file.GetSize() > k100MB)
  {
    // Not actually unsupported, just want to flag large files.
    WriteNewline(out);
    WriteNormal(out, L"WARNING! File is over 100MB.", 0);
    WarnForCurrentFile(WarningType::kUnsupported);
  }

  DumpHeaders(process, pe_file);

  DumpSections(process, pe_file);

  DumpTls(process, pe_file);

  DumpExports(process, pe_file);

  bool has_new_bound_imports_any = false;
  DumpImports(process, pe_file, has_new_bound_imports_any);

  DumpBoundImports(process, pe_file, has_new_bound_imports_any);

  DumpRelocations(process, pe_file);

  DumpStrings(process, pe_file);

  HandleWarnings(path);
}
示例#6
0
void CChunkRenderText::StoreChunks(const std::vector<CChunk*> &Chunks)
{
	// Generate strings
	for (std::vector<CChunk*>::const_iterator it = Chunks.begin(); it != Chunks.end(); ++it) {
		for (int j = 0; j < sizeof(RENDER_FUNCTIONS) / sizeof(stChunkRenderFunc); ++j) {
			if ((*it)->GetType() == RENDER_FUNCTIONS[j].type)
				(this->*RENDER_FUNCTIONS[j].function)(*it, m_pFile);
		}
	}

	// Write strings to file
	WriteFileString(CStringA("; FamiTracker exported music data: "), m_pFile);
	WriteFileString(CFamiTrackerDoc::GetDoc()->GetTitle(), m_pFile);
	WriteFileString(CStringA("\n;\n\n"), m_pFile);

	// Module header
	DumpStrings(CStringA("; Module header\n"), CStringA("\n"), m_headerStrings, m_pFile);

	// Instrument list
	DumpStrings(CStringA("; Instrument pointer list\n"), CStringA("\n"), m_instrumentListStrings, m_pFile);
	DumpStrings(CStringA("; Instruments\n"), CStringA(""), m_instrumentStrings, m_pFile);

	// Sequences
	DumpStrings(CStringA("; Sequences\n"), CStringA("\n"), m_sequenceStrings, m_pFile);

	// Waves (FDS & N163)
	if (m_wavetableStrings.IsEmpty() == FALSE) {
		DumpStrings(CStringA("; FDS waves\n"), CStringA("\n"), m_wavetableStrings, m_pFile);
	}

	if (m_wavesStrings.IsEmpty() == FALSE) {
		DumpStrings(CStringA("; N163 waves\n"), CStringA("\n"), m_wavesStrings, m_pFile);
	}

	// Samples
	DumpStrings(CStringA("; DPCM instrument list (pitch, sample index)\n"), CStringA("\n"), m_sampleListStrings, m_pFile);
	DumpStrings(CStringA("; DPCM samples list (location, size, bank)\n"), CStringA("\n"), m_samplePointersStrings, m_pFile);

	// Songs
	DumpStrings(CStringA("; Song pointer list\n"), CStringA("\n"), m_songListStrings, m_pFile);
	DumpStrings(CStringA("; Song info\n"), CStringA("\n"), m_songStrings, m_pFile);

	// Song data
	DumpStrings(CStringA(";\n; Pattern and frame data for all songs below\n;\n\n"), CStringA(""), m_songDataStrings, m_pFile);

	// Actual DPCM samples are stored later
}
示例#7
0
void CChunkRenderText::StoreChunks(std::vector<CChunk*> &m_vChunks, CFile *pFile)
{
	// Generate strings
	for (unsigned int i = 0; i < m_vChunks.size(); ++i) {
		for (int j = 0; j < sizeof(RENDER_FUNCTIONS) / sizeof(stChunkRenderFunc); ++j) {
			if (m_vChunks[i]->GetType() == RENDER_FUNCTIONS[j].type)
				(this->*RENDER_FUNCTIONS[j].function)(m_vChunks[i], pFile);
		}
	}
	
	// Write strings to file
	WriteFileString(pFile, CString("; FamiTracker exported music data\n;\n\n"));

	// Module header
	DumpStrings(CString("; Module header\n"), CString("\n"), m_headerStrings, pFile);

	// Instrument list
	DumpStrings(CString("; Instrument pointer list\n"), CString("\n"), m_instrumentListStrings, pFile);
	DumpStrings(CString("; Instruments\n"), CString(""), m_instrumentStrings, pFile);

	// Sequences
	DumpStrings(CString("; Sequences\n"), CString("\n"), m_sequenceStrings, pFile);

	// Waves (FDS & N163)
	if (m_wavetableStrings.IsEmpty() == FALSE) {
		DumpStrings(CString("; FDS waves\n"), CString("\n"), m_wavetableStrings, pFile);
	}

	if (m_wavesStrings.IsEmpty() == FALSE) {
		DumpStrings(CString("; N163 waves\n"), CString("\n"), m_wavesStrings, pFile);
	}

	// Samples
	DumpStrings(CString("; DPCM instrument list (pitch, sample index)\n"), CString("\n"), m_sampleListStrings, pFile);
	DumpStrings(CString("; DPCM samples list (location, size, bank)\n"), CString("\n"), m_samplePointersStrings, pFile);

	// Songs
	DumpStrings(CString("; Song pointer list\n"), CString("\n"), m_songListStrings, pFile);
	DumpStrings(CString("; Song info\n"), CString("\n"), m_songStrings, pFile);

	// Song data
	DumpStrings(CString(";\n; Pattern and frame data for all songs below\n;\n\n"), CString(""), m_songDataStrings, pFile);

	// Actual DPCM samples are stored later
}