Exemplo n.º 1
0
void disassemble(const std::string& scmname)
{
	std::ifstream scmfile(scmname.c_str());

	if( !scmfile.is_open() ) {
		std::cerr << "Failed to open " << scmname << std::endl;
		return;
	}

	scmfile.seekg(0, std::ios_base::end);
	int size = scmfile.tellg();
	scmfile.seekg(0);

	SCMByte* byff = new SCMByte[size];
	scmfile.read(byff, size);
	SCMFile scm;
	scm.loadFile(byff, size);
	delete byff;

	try {
		std::cout << "section globals: " << std::hex <<
					 scm.getGlobalSection() << std::endl;
		std::cout << "section models: " << std::hex <<
					 scm.getModelSection() << std::endl;
		std::cout << "section sizes: " << std::hex <<
					 scm.getMissionSection() << std::endl;
		std::cout << "section main: " << std::hex <<
					 scm.getCodeSection() << std::endl;

		dumpModels(&scm);

		dumpCodeSizes(&scm);
		
		SCMOpcodes* opcodes = new SCMOpcodes;
		opcodes->modules.push_back(new VMModule);
		opcodes->modules.push_back(new GameModule);
		opcodes->modules.push_back(new ObjectModule);
		
		dumpOpcodes(&scm, opcodes, scm.getCodeSection(), size);
	}
	catch (SCMException& ex) {
		std::cerr << ex.what() << std::endl;
	}
}
Exemplo n.º 2
0
static void dumpCodeBuff( void (*output)( char ),
                          code_buff *buff )
{
    dis_handle          handle;
    dis_dec_ins         ins;
    char                name[ MAX_INS_NAME ];
    char                ops[ MAX_OBJ_NAME + 24 ];

    DisInit( buff->cpu, &handle );
    while( buff->offset < buff->length ){
        DisDecodeInit( &handle, &ins );
        if( buff->cpu == DISCPU_x86 ) {
            ins.flags |= DIF_X86_USE32_FLAGS;
        }
        DisDecode( &handle, buff, &ins );
        DisFormat( &handle, buff, &ins, DFF_AXP_SYMBOLIC_REG|DFF_PSEUDO, &name, &ops );
        myPrintf( output, "\t%4.4x:", buff->offset );
        dumpOpcodes( output, buff->start+buff->offset, ins.size );
        myPrintf( output, "\t%s\t%s\n", name, ops );
        buff->offset += ins.size;
    }
    DisFini( &handle );
}